in reply to Re: Extract first word from certain lines in a file
in thread Extract first word from certain lines in a file
output:my (@w, $c); local ( $", $_ ) = ", "; do { $_ = <DATA>; if ( defined $_ && !/^Product:/ ) { push @w,(split ' ')[0]; } elsif ( @w ) { print "Product: ", ++$c, "\n@w\n"; @w = (); } } while ( defined $_ ); __DATA__ Product: redball This is for Mike. greenball This is for Dave. Product: smallbox This is for apples bigbox This is for orange
Product: 1 redball, greenball Product: 2 smallbox, bigbox
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Extract first word from certain lines in a file
by CountZero (Bishop) on Oct 26, 2004 at 05:42 UTC | |
by borisz (Canon) on Oct 26, 2004 at 08:03 UTC |