Something new I learned about sed...

I've been trying to figure out how to pick certain line numbers out of a file. For example, if my file is 100 lines long, how do I pick out just the 3rd and 5th line?

Consider the following file:

$ cat test.txt
line a
line b
line c
line d
line e
line f
line g
line h
line i
line j
line k
line l


My original thought was to do the following multiple times:

head -3 test.txt | tail -1 >out.txt
head -5 test.txt | tail -1 >>out.txt


but digging around I found the following in a pretty obscure web page.

$ sed -n '3p;5p' test.txt
line c
line e


Note the semi-colon which lets you perform more then one sed command.
Thanks to help from this following link (note where it said "other seds").

Until next time...Rich

Comments

Popular Posts