Kyle R . Burton on Wed, 29 Nov 2000 16:06:10 -0500 (EST)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] scanning a line


> hi,
> we all love grep and that's for a reason. however, sometimes i wish to
> scan a single line for a pattern and only get the pattern back. simply
> example:
> 
> the pattern "[0-9]*" should return the string in the second column
> when applied to the string in the first column:
> 
> aaaa9879aaaaaa0870aaaaaaaaaaa09    =>  9879 0870 09
> aa908798986986aaaaaaaaaaaaaaaaa    =>  908798986986
> 
> in the first case, it would be even better to sort of include some
> 'cut' features, such that i could say give me the 2nd occurrence of
> the pattern, and it would only return 0870.
> 
> is this possible? i.e. is there a command to do this? or a simple
> hack? this needs to be shell script...

Try awk or perl.  I don't know awk, but this should do it for perl:


perl -ne 'if(@a=(/\d+/g)) { print join(" ",@a),"\n"; }' < file.txt
cmd | perl -ne 'if(@a=(/\d+/g)) { print join(" ",@a),"\n"; }'

k

-- 
------------------------------------------------------------------------------
"From a certain point onward there is no longer any turning back.  That is the
 point that must be reached."   -- Kafka
mortis@voicenet.com                            http://www.voicenet.com/~mortis
------------------------------------------------------------------------------


______________________________________________________________________
Philadelphia Linux Users Group       -      http://www.phillylinux.org
Announcements-http://lists.phillylinux.org/mail/listinfo/plug-announce
General Discussion  -  http://lists.phillylinux.org/mail/listinfo/plug