Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract lines from a file 1

Status
Not open for further replies.

Diogo

Technical User
Mar 22, 2001
143
PT
Hello.

Can some one help me.

I have one file with 30 lines, and i want to obtain the lines between line number 15 and line number 18.

Is there any way?

Thanks any way.
 
And the awk way:
awk 'NR==15,NR==18;NR>18{exit}' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
hi, I wanted to do something similar to this, but I want to extract a random line number. How would I go about doing this? I have tried to use:

sed -n $RANDOMp sonnets.txt

but that doesnt seem to work. Thanks in advance
 
Also, how would I apply modulus to it. Because I want random to return a number <2156. I want put $RANDOM%2156, but I am not sure how to use modulus in scripting. Thanks again
 
nevermind, I answered my own question. My solution was:

sed -n $(($RANDOM % 2156))p filename

if anyone was interested =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top