Getting a single line by line number with sed

20.05.2006 at 22:50

Well it turned out that i am not yet that comfortable in shell scripting. I often get error messages which indicating the line numbers which a problem occurs and i wanted to print that single line of a given file. So i ended up with a solution which was built upon a combination of head and tail, before i finally realised that sed is the right tool for the job.

sed -ne 7p filename

Prints out line number 7 of filename, if you want some context which is likely then supply a range instead of a single line, which can be accomplished as follows.

sed -ne 5,10p filename

Marc

Comments (0)

There are currently no comments available