Let’s see some of sed ’s editing capabilities in action using examples.
The format for the print command is [address[,address]p. To display a line of text you can supply sed with a line number and sed will display it for you.
$ sed '2p' quote.txt The honeysuckle band played all night long for only $90. It was an evening of splendid music and company. Too bad the disco floor fell through at 23:10. The local nurse Miss P.Neave was in attendance.
What went wrong there? We said we wanted line 2 and issued the p to print that line only, but it’s printed all the lines in the file. To fix this we use the -n option to explicitly print addressed (matched) lines.
$ sed -n '2p' ...