Follow @rb_rudra

Thursday, 18 October 2012

Given a list of text lines in a file, to display the first 10 lines:

Given a list of text lines in a file, to display the first 10 lines:

head foo.txt
To display the last 10 lines:
tail foo.txt
Try -n option to specify the number of lines to display:
tail -n3 foo.txt  # the last 3 lines
head -n4 foo.txt  # the first 4 lines 
And don’t forget, the '+' in tail and '-' in head:
tail -n+10 foo.txt  # start from the 10th line til the last
head -n-10 foo.txt  # print all, except the last 10 lines 
Updates: Inspired by mysurface’s comment, to display the file from 4th line to to 10th line:
head -n10 foo.txt | tail -n+4  # 4th line to 10th line.

No comments:

Post a Comment