by chaps · 1y ago · 0 comments
Like: printing all but one column somewhere in the middle. It turns into long, long commands that really pull away from the spirit of fast fabrication unix experimentation.
jq and sql both have the same problem :)
$ echo "one two three four five" | awk '{$3="";print}'
one two four five sed 's/ / /g'Whence perl.
Within infrastructures where perl is installed on 95% of hosts, that 5% really bites you in the ass and leads to infrastructure rot very quickly. You're kinda stuck writing and maintaining two separate scripts to do the same thing.
The following command is handy for grepping the output:
cat mydata.json | json_pp cut -d " " -f1-2,4-5 file.txt
where file.txt is: one two three four five
and the return is: one two four fiveThat's why I use Perl instead (besides some short one liners in awk, which in some cases are even shorter than the Perl version) and do my JSON parsing in Perl.
This
diff -rs a/ b/ | ask '/identical/ {print $4}' | xargs rm
is one of my often used awk one liners. Unless some filenames contain e.g. whitespace, then it's Perl again
And I use this "historic" one liner only when I know about the contents of both directories. As soon as I need a "safer" solution I use a Perl script and pattern matching, as I said.
diff -rs a/ b/ | perl -ane '/identical$/ && unlink $F[3]'