For example, I have a file
1
2
3
then I want to output from 2nd row to tail
How can I do it in linux
The first line of a file can be skipped by using various Linux commands. As shown in this tutorial, there are different ways to skip the first line of a file by using the `awk` command. Noteably, the NR variable of the `awk` command can be used to skip the first line of any file.
Using head to get the first lines of a stream, and tail to get the last lines in a stream is intuitive. But if you need to skip the first few lines of a stream, then you use tail “-n +k” syntax. And to skip the last lines of a stream head “-n -k” syntax.
' means: delete the first line in file "file_name" at place and backup to file. (just like edit file and delete first line directly. )
wc stands for word count. As the name implies, it is mainly used for counting purpose. It is used to find out number of lines, word count, byte and characters count in the files specified in the file arguments. By default it displays four-columnar output.
tail -n+2 my_file
will output all the lines in myfile
starting with line 2. (-n2
would show you the last two lines.)
tail
has lots more options. Type man tail
for complete documentation.
shorter with
$ sed 1d filename
or with awk
$ awk 'NR>1' filename
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With