How do i not view a line in unix under a file

November 29, 2010 at 05:01:21
Specs: Windows XP
script or command to view the 54th and 56th line and not the 55th?

See More: How do i not view a line in unix under a file

Report •

November 29, 2010 at 08:43:04
I am assuming that you are asking for a unix solution? This sed command will print only lines 54 and 56. The first sed prints lines 54 to 56 to a pipe and another sed command. That result is only 3 lines so do NOT print the 2nd line which results in lines 54 and 55:


sed -n '54,56p' datafile.txt |sed -n '2!p'

Another solution is to use awk and only print lines 54 or 56

awk ' NR == 54 || NR == 56 ' datafile.txt

NR is the number of records that awk has read.

Report •

September 15, 2011 at 13:02:53
Do I feel dumb or what?! I call blemishes on my own posts when I see them. While what I originally posted was correct, I should have also included this as the optimal solution:

sed -n -e '54p' -e '56p' datafile.txt

Report •
Related Solutions

Ask Question