i'm trying to print specific lines from a file using only one command
for example:
a file contains 30 lines , i wish to print the content of lines 13, 14, 15, 16??
what command to use for that?

9 Years
Discussion Span
Last Post by Salem

Thx for the quick answer Salem.
i looked the man pages for those command, but couldnt figure out how to use them for my purpose.
could you add an example on one of those commands?


sed with the -n option and the "p" "operator". Try reading the man page for sed again, then post your attempt here.


i actually did read the man pages but couldnt understand anything from this:
-n, --quiet, --silent
suppress automatic printing of pattern space.

i've tried the following and it worked for my example:
sed -n 13,16p file

from what i understand it prints the given range?
What if i want to print random lines that arent one after the other, is that possible?


Well, that's what you do. Take a look at the manual again, and see what other types of "patterns" that you can use in the same position that you currently have "13,16".


We're only going to throw you so many bones before we expect you to start reading the manuals and figuring out how to do this stuff.

In fact, just go read the manuals. No, you won't remember the details, but you'll probably remember enough to recognise that you might have read something like the answer to your problem before.
Then you go on a more detailed hunt to find exactly what you're looking for.

If you can remember roughly what each tool is capable of, then you can RTM to find out the detail when you need it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.