Tab separated values in awk

Tab separated values in awk

You need to set the OFS variable (output field separator) to be a tab:

echo $line | 
awk -v var=$mycol_new -Ft BEGIN {OFS = FS} {$3 = var; print}

(make sure you quote the $line variable in the echo statement)

Make sure theyre really tabs! In bash, you can insert a tab using C-v TAB

$ echo LOAD_SETTLED    LOAD_INIT       2011-01-13 03:50:01 | awk -F$t {print $1}
LOAD_SETTLED

Tab separated values in awk

You can set the Field Separator:

... | awk BEGIN {FS=t}; {print $1}

Excellent read:

https://docs.freebsd.org/info/gawk/gawk.info.Field_Separators.html

Leave a Reply

Your email address will not be published.