[Lvlug] awk question
Hanuman
fingolfin at thelinuxlink.net
Thu Aug 11 11:50:45 EDT 2005
On Fri, 5 Aug 2005, Brian K wrote:
> Thanks to all who helped me out! At least I have some things to think about
> now.
>
> Brian
I might add (and I'm not even good at Perl):
#!/usr/bin/perl
use strict;
use warnings;
while (<>) {
chomp; # Me being a pedantic asshole
if (/mapper/) { print ${ [ split ' ', <> ] }[3], "\n"; }
else { split ' '; print $_[4], "\n"; }
}
Now I have to go look at all those l33t runtime options for Perl; they
should make my scripts a lot smaller.
There are two kinds of text processing you can do. There's batch
processing, the kind of repetitive crap that would give you carpal
tunnel if you had to do it by hand. sed is ideal for that. Then there's
the kind of text processing where decisions have to be made; you come to
a fork in the road, so to speak, and you have to pick a route. In my not
so humble opinion, Perl is best suited for this task, period. If file
processing is involved too, a decent Bourne-compatible shell belongs in
there as well. IMO, that is.
I don't want to seem like I'm kibitzing in your choice of tools,
approaches to programming, philosophy, or color of underwear. Lord
knows, I never cared for that myself. I do, however, believe you would
do well to invest some time in learning Perl. There are lots of free
resources for doing this, you can try http://learn.perl.org, and another
excellent site I just found: http://www.steve.gb.com/perl/. I am
wgetting it for storage as I type. I have some other stuff; contact me
off list if you're interested.
I say this because awk is hopelessy inadequate for me. It seems every
attempt to move beyond splitting a record and printing a field crashed
and burned in a horrible train wreck of syntax errors. I just couldn't
hack it, I guess. Don't let the FUD scare you:
On 3 Aug 1997 13:17:43 GMT, Want More Dates???
<tracy78 at kilgrona.com> wrote:
>Learn the SECRET to Attract Women Easily
>
>The SCENT(tm) Pheromone Sex Attractant For Men to Attract Women
The scent of awk programmers is a lot more attractive to women than
the scent of perl programmers.
--
Mike Brennan
This is patently false. Perl programmers usually have pheromones ponging
off them.
OTOH, you could also refactor the problem so that it turns into TWO
batch jobs instead of one sophisticated, logic-oriented one.
df | sed -e '/mapper/N' -e 's/\n//' | awk '{ print $5 }'
P.S. - Check out the other stuff on that steve site. So here's this guy
who knows all this geek stuff, and he's not balding, fat, and ugly.
- Hanu-mizzle
More information about the Lvlug
mailing list