Here's a similar question but I ran into a problem that was not addressed in the question. How to replace the content of a specific column with awk?

I want to do something similar, however my file is tab delimited instead of space delimited. I want to change field 3. Lets say my file looks like this:


Lets say I want to change field 3 to AD

awk '{$3 = "AD"; print}' infile > outfile

my output is

NAME\tNUMBER\tAD SEQ ... ... ... ... ... ...

my tabs turn into spaces after the replaced I'm sure I can just tr the output file but I want to know what causes awk to change the field delimiter.

expected output:


1 Answer 1


You need to set Output Field Separator, to tab \t:

One way to do it is with -v option:

awk -vOFS='\t' '{$3 = "AD"; print}' file

another possibility inside awk, say in the BEGIN block:

awk 'BEGIN{OFS="\t"}{$3 = "AD"; print}' file

If you don't set OFS, then awk by default uses single space as a field separator.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .