1834445 Members
2810 Online
110067 Solutions
New Discussion

Re: sed or awk ???

 
SOLVED
Go to solution
MikeL_4
Super Advisor

sed or awk ???


Is there a way within sed and/or awk, (or any other command for that matter) to print certain lines within a file ??
Say in myfile I want to list lines 20 through 23 of the file only ??

Thanks
12 REPLIES 12
Pete Randall
Outstanding Contributor
Solution

Re: sed or awk ???

See attached

Pete

Pete
James R. Ferguson
Acclaimed Contributor

Re: sed or awk ???

Hi:

# sed -n -e 20,23p filename

Regards!

...JRF...
John Poff
Honored Contributor

Re: sed or awk ???

Hi,

Here is one way to do it in Perl:

perl -ne 'print unless (($.<20) or ($.>23));' filename

JP

James R. Ferguson
Acclaimed Contributor

Re: sed or awk ???

Hi (again):

...and if you like 'awk':

# awk 'NR >=20 && NR <= 23' filename

Regards!

...JRF...
curt larson_1
Honored Contributor

Re: sed or awk ???

how about:
awk '
NR > 19 {print;}
NR > 23 {exit;)
'
Chris Vail
Honored Contributor

Re: sed or awk ???

In unix there is always more than one way to do any particular job. Others have contributed sed and awk scripts. Here's another: head -23 myfile|tail -3. Try it.


Chris
H.Merijn Brand (procura
Honored Contributor

Re: sed or awk ???

John, you should know better by now :)

# perl -ne '20..23 and print' file

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Stanimir
Trusted Contributor

Re: sed or awk ???

Hi,Pete!
I have taken your attachment - it is
cool&great little thing - Thanx! :)
But I try to connect to: www.wollery.demon.co.uk
to see more like that - without success.
Any information?
Regards, Stan



MikeL_4
Super Advisor

Re: sed or awk ???

Thanks all for your assistance..
H.Merijn Brand (procura
Honored Contributor

Re: sed or awk ???

You can thankpeople by assigning points.

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
MikeL_4
Super Advisor

Re: sed or awk ???

how do you assign points ??
H.Merijn Brand (procura
Honored Contributor

Re: sed or awk ???

In the header of each post, you see a dropdown box. Click it, and choose the appropriate amount for each post. 10 = best answer, it solved my problem, 0 = thanks, but it didn't help at all.

When youve done all, hit the (-> SUBMIT) button at the left bottom

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn