[techtalk] help with sorting text in a file
Sean McAfee
mcafee at umich.edu
Sun May 14 23:10:34 EST 2000
Gene Dolgner <edolgner at execpc.com> wrote:
>alissa bader wrote:
>> actually I needed to grab a particular string. For
>> example, all patterns matching QAA:
[snip]
>> anyway the easiest way to do this (and the way I did
>> it before but forgot :>) was to use a "cut" on this
>> file. (and someone on this list mailed me about "cut!"
>> :>) Since everything I was looking for was in the same
>> place on each line.
>> thanks again for everyone's help with this!
>Try this ...
>cat file | grep 'QAA' | sed s/^.*QAA/QAA/ | sed s/:.*$//
I'm starting to think I'm the only Perl-slinger on this list. This task is
well within the class of jobs that Perl particularly excels at:
perl -lane 'print $1 if $F[5] =~ /^QAA(\d+):/'
-a (autosplit) is a relatively infrequently-used Perl switch that causes it
to split input lines on whitespace into the global @F array, making it
behave somewhat like awk does.
--
Sean McAfee | GCS d->-- s+++: a27 C++ US+++ P+++$ L++ E- W+ N++ |
| K w--- O? M- V-- PS+ PE Y+ PGP?>++ t+() 5++ X R+ | mcafee@
| tv+ b++ DI++ D+ G e++ h r---* y+>++ | umich.edu
More information about the Techtalk
mailing list