I am stuck. Say I have tab separated file with 4 columns.
A326931873 2014-10-26 09:55:28.000 N06 D00030131051410
A326931902 2014-10-26 09:56:10.000 N06
And want to replace empty field at the end of the line with \N. The result should be
A326931873 2014-10-26 09:55:28.000 N06 D00030131051410
A326931902 2014-10-26 09:56:10.000 N06 \N
I have tried awk -F'\t' 'BEGIN {sub("", "\N", $4); print}' file
, awk -F'\t' 'BEGIN {sub(/^&/, "\N", $4); print}' file
and alike with no luck.
Update1: As suggested I have also tried using number of fields, but awk -F"\t" 'NF<4 {print}' file
returns no results, that is all lines have four fields.
Update2: cat -vET file
shows
A326931873^I2014-10-26 09:55:28.000^IN06^ID00030131051410^M$
A326931902^I2014-10-26 09:56:10.000^IN06^I^M$
Update3: after removing carriage returns cat -vET file
shows
A326931873^I2014-10-26 09:55:28.000^IN06^ID00030131051410$
A326931902^I2014-10-26 09:56:10.000^IN06^I$
and any of the suggested solutions does not work.
So I have figured out the answer myself
awk -F'\t' -v OFS='\t' 'length($4)==1{$4="\N"}1' file