in reply to Performing search and replace on an output file prior to printing
The way I'd do it is put the values in an array, process the array and print it with either $, or $" set to "\t".
BEGIN { $,="\t"; print "Head1".."Head4"; } @v = ("w", $F[2], $F[3], length($F[9])); $v[0] = "c" and $v[2]++ if $F[1] =~ /83/; v[1] =~ tr/ACF/BDG/; print @v if $F[1] =~ /99|83/;
Untested, since I didn't have input data :).
"Head1".."Head4" is a little bit of perl magic to print your headers. tr will replace every occurrence of the letters, not just the first like you did, but you get the idea.
Edit: removed useless slice on first definition of @v.
Edit: replaced all the $v{X} by $v[X]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Performing search and replace on an output file prior to printing
by GotToBTru (Prior) on Jan 26, 2016 at 13:38 UTC | |
by choroba (Cardinal) on Jan 26, 2016 at 13:41 UTC | |
by Eily (Monsignor) on Jan 26, 2016 at 16:18 UTC | |
|
Re^2: Performing search and replace on an output file prior to printing
by Anonymous Monk on Jan 27, 2016 at 13:44 UTC |