Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tail all lines except first row [duplicate]

Tags:

linux

bash

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

like image 738
Sato Avatar asked Dec 29 '15 04:12

Sato


People also ask

How do I skip the first row in Unix?

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.

How do I skip a line in a bash script?

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.

What does SED 1d do?

' means: delete the first line in file "file_name" at place and backup to file. (just like edit file and delete first line directly. )

How does wc command work?

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.


2 Answers

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.

like image 187
rici Avatar answered Oct 09 '22 13:10

rici


shorter with

$ sed 1d filename

or with awk

$ awk 'NR>1' filename
like image 28
karakfa Avatar answered Oct 09 '22 13:10

karakfa