using sed to get the xth, yth, and zth line of a text file
I know you can use sed
to get the nth line of a text file as follows:
sed -n '30p'开发者_如何学Go foo.txt
will output the 30th line of foo.txt
However, suppose I'm interested in the 30th, 39th, 43rd lines of foo.txt
? Is there a way to string this together in sed
?
Thanks.
Sure is...
sed -n '30p;39p;43p' foo.txt
If they are in a contiguous range, say 39-42 you can do something like this:
sed -n '39,42p' foo.txt
精彩评论