4 ms·
I code in Perl at my day job, and I still use awk and grep. Sometimes it's quicker to do it in awk than perl, especially when you're doing it in command line a
by caw 15y ago
I code in Perl at my day job, and I still use awk and grep. Sometimes it's quicker to do it in awk than perl, especially when you're doing it in command line and have to figure out quotes.
awk -F, '{print $3}' foo | xargs -I{} echo 'command -x -y -z {}'
perl -e 'open F, "<foo"; while(<F>) { my($a,$b,$c,@rest) =split /,/; system("command -x -y -z $c"); }'
I think I could do the split into an array and then take the third element, but I'm just trying to do an elementary example. When you want to do more things to this argument you necessarily have to grow this, and at one point I got to the point where I started having to escape quotes. That's rather difficult to read when you're just trying to do something quick in the command line and you mismatch a pair.
- ajays 15y agoInstead of opening the file "foo" by hand, you can use Perl's "awk mode" thusly: perl -lane 'system("command -x -y -z $F[2]")' foo