I recently learned that you can make multiple statements in awk/gawk, separating them by semicolons, like many decent programming languages. This makes it relatively easy to assign various attributes and functions on extracted text to produce final output. Yes, even with a custom field splitter.
Managing quotation marks is still tricky, though.
I gotta share! Example for illustrative purposes:
gawk -F’\t’ ‘{sub(“old-value”, “new-value”, $1); gsub(“ “, “-“, $2); match($1, /^[a-z]+/,newArray); newVariable = $2 “ new text ” newArray[1]; print “My changed output: “ newVariable;}’ input-file.txt
In this example I’ve specified a field separator (specifying the creation of $ numbered variables from input), used 3 functions (one creating an array variable), assigned a variable, and output text to the command line—with text from the given input file. Changing the “print” statement to a “system” function (i.e. system(newVariable)) lets you run your output as commands. So very handy.
#CommandLine #Awk #Gawk