Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9259261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:36:46+00:00 2026-06-18T12:36:46+00:00

I am using a bash script where I must store the last n-2 lines

  • 0

I am using a bash script where I must store the last n-2 lines of a file in a variable.
The command I use for this is

last_n2_lines=`tail -n+3 $file`

Now whenever i echo the $last_n2_lines variable, I get all the lines of my file in a single line. How can I get the same formatting as I had in my original file. I tried printf but it just prints the first field.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:36:48+00:00Added an answer on June 18, 2026 at 12:36 pm

    Try this:

    echo "$last_n2_lines"
    

    echo doesn’t see the original value in your variant, because it’s broken down to argv array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a bash script with display command, after upgrading to Ubuntu 10.10 this
I have an xml file that I want to configure using a bash script.
In a bash script in Linux, I am using flock [the command flock, not
I am writing a Bash script and using Expect to do sftp. Now in
I am using the following command in a bash script to loop through directories
I want to insert a big chunk of code using a bash script. This
I am using Bash script to read line by line from a text file,
I am using a bash script to launch a ruby script. this works very
I'd like to change the file name suffix from files (using a bash script),
I use a bash script to spawn screen sessions in detached mode (using -d

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.