help-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Insertion of extra OFS character into output string


From: H
Subject: Insertion of extra OFS character into output string
Date: Mon, 13 Mar 2023 21:10:28 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

I am a newcomer to awk and have run into an issue I have not figured out yet... 
My platform is CentOS 7 running awk 4.0.2, the default version.

The following awk statement generates an extra tab character between fields 1 
and 2, regardless of the data in the file:

awk 'BEGIN{FS=","; FPAT="([^,]*)|(\"[^\"]+\")"; OFS="\t"} {$1=$1; gsub(/"/, 
""); print}' somefile.csv

If i change the statement to:

awk 'BEGIN{FS=","; FPAT="([^,]*)|(\"[^\"]+\")"; OFS="\t"} {$2=$2; gsub(/"/, 
""); print}' somefile.csv

an extra OFS character is inserted between fields two and three. I can add that 
removing the gsub() in either of the two examples does not affect the results.

Might this be a bug in 4.0.2 or a feature I have not yet understood?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]