Print all Fields with AWK separated by OFS

This is a variation on the first style: echo “1 2 3 4″ | gawk ‘BEGIN { OFS=” 🙁 “}; {$1=$1; print $0}’ Results: 1 🙁 2 🙁 3 🙁 4 Explanation: the $1=$1 is to rebuild the record, using the current OFS (you can also see http://www.gnu.org/software/gawk/manual/gawk.html#Changing-Fields) Update: (suggested by @EdMorton and @steve) This … Read more

awk: find minimum and maximum in column

Awk guesses the type. String “10” is less than string “4” because character “1” comes before “4”. Force a type conversion, using addition of zero: min=`awk ‘BEGIN{a=1000}{if ($1<0+a) a=$1} END{print a}’ mydata.dat` max=`awk ‘BEGIN{a= 0}{if ($1>0+a) a=$1} END{print a}’ mydata.dat`

String comparison in awk

Sure it can: pax$ echo ‘hello goodbye’ | gawk ‘{if ($0 == “hello”) {print “HELLO”}}’ HELLO You can also do inequality (ordered) testing as well: pax> printf ‘aaa\naab\naac\naad\n’ | gawk ‘{if ($1 < “aac”){print}}’ aaa aab

ignorecase in AWK

Add IGNORECASE = 1; to the beginning of your awk command like so: bash-3.2$ echo “Create” | awk ‘/^create/;’ bash-3.2$ echo “Create” | awk ‘IGNORECASE = 1;/^create/;’ Create

tech