Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the opposite of head? I want all but the first N lines of a file

People also ask

What is the opposite of tail in Linux?

head is a basic opposite of tail in relation to what part of the file operations are performed on. By default, head will read the first 10 lines of a file.

How do I see the last 10 lines of a file in Linux?

tail [OPTION]... [ Tail is a command which prints the last few number of lines (10 lines by default) of a certain file, then terminates. Example 1: By default “tail” prints the last 10 lines of a file, then exits.

How do you find the last line of a file in Linux?

To display the last part of the file, we use the tail command in the Linux system. The tail command is used to display the end of a text file or piped data in the Linux operating system. By default, it displays the last 10 lines of its input to the standard output. It is also complementary of the head command.

What is use of tail command in Linux?

The basic functionality of the Linux tail command is to output the end of a file. Typically, new data added to a file ends up at its tail (i.e., the end). So, the Linux tail command allows us to check if a file has new data attached. Therefore, the Linux tail command is a popular tool to evaluate and monitor log files.


tail --help gives the following:

  -n, --lines=K            output the last K lines, instead of the last 10;
                           or use -n +K to output lines starting with the Kth

So to filter out the first 2 lines, -n +3 should give you the output you are looking for (start from 3rd).


Assuming your version of tail supports it, you can specify starting the tail after X lines. In your case, you'd do 2+1.

tail -n +3

[mdemaria@oblivion ~]$ tail -n +3 stack_overflow.txt
CCCC
DDDD
EEEE

A simple solution using awk:

awk 'NR > 2 { print }' file.name

Try sed 1,2d. Replace 2 as needed.


tail -n +linecount filename will start output at line linecount of filename, so tail -n +3 filename should do what you want.