Why does my tail command -n NUM not work

0 votes

I want to understand the following command in Linux:

# tail -n+454 /path/to/a/file | head -n 6

I expect that tail -n+454 /path/to/a/file prints the lines, starting at line 454 and the following 5 lines.

The | sends that output to the head as an input. Then only the first 10 lines are taken.

Finally, -n 6 defines that only the first 6 lines are printed to the screen.

Did I translate the command correctly?

Now I have the following problem: Let's assume I have a file and the following line in it:

# Step #6: Configure output plugins

I want to print the 5 lines immediately before that line (including that line).

First I checked, what line number my line in question has:

nl /path/to/a/file | grep output

enter image description here

The line number is 459.

I want the 5 lines preceding line 459 as well as line 459 itself (that is, lines 454 to 459).

The command tail -n+454 /path/to/a/file | head -n 6 gives me the following output:

enter image description here

This is line 380 to 384:

enter image description here

I expected to get lines 454 to 459. What did I not understand? Is my command not correct?

Apr 13, 2022 in Linux Administration by Soham
• 9,700 points
414 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Linux Administration

0 votes
1 answer

Installation fails on xenial "Repository does not have a release file"

This bug is missing log files that ...READ MORE

answered May 23, 2019 in Linux Administration by Ishaan
591 views
0 votes
1 answer

“cd” doesn't work in my shell script

One way to get around this is ...READ MORE

answered May 24, 2019 in Linux Administration by Shubham
• 13,490 points
1,535 views
0 votes
1 answer

group apache does not exist - using root.

Hi@akhtar, When we install apache wevserver in our ...READ MORE

answered Apr 14, 2020 in Linux Administration by MD
• 95,440 points
3,463 views
0 votes
1 answer

Error lscpu: command not found.

Hi@akhtar, By default, this command should present in ...READ MORE

answered Oct 12, 2020 in Linux Administration by MD
• 95,440 points
1,295 views
0 votes
1 answer

Amazon Linux: apt-get: command not found

Amazon Linux is CentOs-based which means that ...READ MORE

answered Feb 11, 2022 in Linux Administration by Soham
• 9,700 points
2,078 views
0 votes
0 answers

What killed my process and why?

This happened two times. I asked if ...READ MORE

Apr 13, 2022 in Linux Administration by Aditya
• 7,680 points
298 views
0 votes
1 answer
0 votes
1 answer

How do I set variable if a specific package version is installed in CFEngine?

Here is what you can do.Just use packagesmatching to ...READ MORE

answered Jul 12, 2018 in Other DevOps Questions by Atul
• 10,240 points
959 views
0 votes
2 answers

Install postgreSQL on Ubuntu

Follow the below commands to install PostgreSQL (PSQL) ...READ MORE

answered Nov 12, 2020 in Database by Prachi
• 140 points
930 views
0 votes
1 answer

Access progrs prompt without switching accounts

Use the following to get the postgres prompt ...READ MORE

answered Mar 22, 2019 in Database by Mahi
652 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP