Wednesday, 24 April 2013

Unix: Print all lines except last 5lines of a file -- head Command


Here is a test file :

$ cat test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 $

Now. 'head' command can be used to print top five lines as follows:

$ head -5 test
1
2
3
4
5
 $

Lets say our while reading output of a log file, our requirement  is to print all lines except last five lines , then also 'head' command can help as follows:

$ head -n -5 test
1
2
3
4
5
6
7
8
9
10
11

No comments:

Post a Comment