5 ms·
Once I learned Perl I never used awk or sed again. Even for one liners with the -n -p -a options you can easily write one liners in Perl that are concise as tho
by ceronman 9y ago
Once I learned Perl I never used awk or sed again. Even for one liners with the -n -p -a options you can easily write one liners in Perl that are concise as those in Awk.
- raldi 9y agoHow do you write awk '{print $3 ":" $1 " " $2}' in Perl?
- troydj 9y agoOne way would be: perl -nae'printf("%s:%s %s\n",$F[2],$F[0],$F[1])'
- raldi 9y agoI would not call that "as concise as awk"
- kazinator 9y agoLisp: $ txr -e '(awk ((prn `@[f 2]:@[f 0] @[f 1]`)))' 1 2 3 3:1 2 How about input from a string stream? At the REPL: 1> (with-in-string-stream (*stdin* "1 2 3") (awk ((prn `@[f 2]:@[f 0] @[f 1]`)))) 3:1 2 nil It pays not to have awk be some some canned global behavior enabled by a command line option.
- kazinator 9y agoAnother way, without using a quasiliteral: just set the output field separator (ofs) to empty string, and prn: txr -e '(awk (:set ofs "") ((prn [f 2] ":" [f 0] " " [f 1])))' This is like: awk -v OFS= '{print $3, ":", $1, " ", $2}'
- jwilk 9y agoperl -aE 'say "$F[2]:$F[0] $F[1]"'