Using sed to get the xth, yth and zth lines of a text file

I know that you can use sedto get the nth line of a text file as follows:

sed -n '30p' foo.txt

will output the 30th line foo.txt

However, suppose I'm interested in 30, 39, 43 lines from foo.txt? Is there a way to tie this together in sed?

Thank.

+3
source share
1 answer

Of course...

sed -n '30p;39p;43p' foo.txt

If they are in an adjacent range, say 39-42, you can do something like this:

sed -n '39,42p' foo.txt
+4
source

Source: https://habr.com/ru/post/1781753/


All Articles