o.k., I admit it, I suck dead donkey dicks in hell at this. I know I can do gooder - maybe you can help. The perl below works, I just think its real ugly and I can't stand the thought that the same thing using awk is simply: cmd | awk '{ if ($1 ~ /^[0-9]*$/) {print $2}}' >> $outlist One place I'm lost is with embedding carriage returns, which awk does so nicely. I played with arrays, stripping extra \n's after the loop, then after adding the stupid if statement below to prevent the extra blank line, I just gave up thinking I need a really good flogging. It was at this point I started to regret every brain cell I lost between 1976 and 1986, so I decided to ask you so I could get on with my life... open( IN, "$cmd |"); while (<IN>) { ($f1,$f2) = split(' ', $_); if ( $f1 =~ /^[0-9]*$/ ) { if ( $list ) { $list = "$list\n$f2" } else { $list = $f2 } } } close IN; open ( OUT, ">$oulist"); print OUT "$list"; close OUT; thanks, Mike
If you want to, STDIN and STDOUT can be used (and are assumed). while (<>) { # keep lines that start with digits print $1 if m/^[0-9]+ ([^ ]+)$/; } --Skip -----Original Message----- From: wlug-admin@mail.wlug.org [mailto:wlug-admin@mail.wlug.org]On Behalf Of Mike Peckar Sent: Tuesday, December 04, 2001 10:17 AM To: wlug@mail.wlug.org Subject: [Wlug] perl wus o.k., I admit it, I suck dead donkey dicks in hell at this. I know I can do gooder - maybe you can help. The perl below works, I just think its real ugly and I can't stand the thought that the same thing using awk is simply: cmd | awk '{ if ($1 ~ /^[0-9]*$/) {print $2}}' >> $outlist One place I'm lost is with embedding carriage returns, which awk does so nicely. I played with arrays, stripping extra \n's after the loop, then after adding the stupid if statement below to prevent the extra blank line, I just gave up thinking I need a really good flogging. It was at this point I started to regret every brain cell I lost between 1976 and 1986, so I decided to ask you so I could get on with my life... open( IN, "$cmd |"); while (<IN>) { ($f1,$f2) = split(' ', $_); if ( $f1 =~ /^[0-9]*$/ ) { if ( $list ) { $list = "$list\n$f2" } else { $list = $f2 } } } close IN; open ( OUT, ">$oulist"); print OUT "$list"; close OUT; thanks, Mike _______________________________________________ Wlug mailing list Wlug@mail.wlug.org http://mail.wlug.org/mailman/listinfo/wlug
How about this one: cmd | perl -lne 'BEGIN{open(O,">>out")||die "open:$!"} print O $1 if (/^\d* (\S*)/)' The longest part of that is the handling of the output file. :) Just curious, what is this for? -- Randomly Generated Tagline: "I don't know if all the people in New England are repressed, but I knew a girl from New Hampshire, now she wasn't repressed, she could do long division with her thighs." - Joe Bob Briggs
Thanks for your help. What I was trying to do was to parse a command's output, pulling the second field from lines whose first field contains a number and outputing that 2nd field to an external file with one entry on each line. This to build a configuration file that will be read by another program. What I was struggling with, and still am after all your replies, is the output file. I seem to have to do crazy things to avoid extra blank lines in the file: Note also that this is a cross platform application: for some reason, perl 5.6.0 on NT does wierd interpretations of the variables within the reg exprs? Mike
participants (4)
-
Mike Peckar
-
Mike Peckar
-
Skip Gaede
-
Theo Van Dinter