I am trying to add field headers to a file in-place using gawk
. The input file
is tab delimited so I added that to the command. If I substitute gawk -i inplace
with just awk
the command runs but the file
is not updated. I know awk
doesn't have an in-place edit like sed
, but can gawk
be used or is there a better way?
gawk -i inplace '
BEGIN {FS = OFS = "\t"
}
NR == 1 {
$1= "Chr"
$2= "Start"
$3= "End"
$4= "Gene"
}
1' file
file (input file to update)
chr7 121738788 121738930 AASS
chr7 121738788 121738930 AASS
chr7 121738788 121738930 AASS
desired output
Chr Start End Gene
chr7 121738788 121738930 AASS
chr7 121738788 121738930 AASS
chr7 121738788 121738930 AASS
I was using the SO Q&A awk
save modifications in place as a guide but was not able to solve my issue.