News for hackers. Stuff that matters.
Re:Awk vs. Perl (2009) by ceronman on Tuesday June 27, 2017 @04:22PM (#14649025)
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.
Re:Awk vs. Perl (2009) by raldi on Tuesday June 27, 2017 @05:13PM (#14649503)
How do you write

    awk '{print $3 ":" $1 " " $2}'
in Perl?
Re:Awk vs. Perl (2009) by jwilk on Tuesday June 27, 2017 @06:05PM (#14649962)

  perl -aE 'say "$F[2]:$F[0] $F[1]"'
Re:Awk vs. Perl (2009) by raldi on Tuesday June 27, 2017 @06:11PM (#14650021)
That's indeed concise, but it doesn't work. I think you need -naE
Re:Awk vs. Perl (2009) by jwilk on Tuesday June 27, 2017 @06:15PM (#14650051)
-a implies -n since v5.19.3.
Re:Awk vs. Perl (2009) by troydj on Tuesday June 27, 2017 @05:47PM (#14649800)
One way would be:

   perl -nae'printf("%s:%s %s\n",$F[2],$F[0],$F[1])'
Re:Awk vs. Perl (2009) by raldi on Tuesday June 27, 2017 @05:52PM (#14649853)
I would not call that "as concise as awk"
Re:Awk vs. Perl (2009) by kazinator on Tuesday June 27, 2017 @06:06PM (#14649966)
Lisp:

  $ 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.
Re:Awk vs. Perl (2009) by kazinator on Tuesday June 27, 2017 @08:22PM (#14650780)
Another 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}'