I want to use awk to translate a CSV file into a new CSV file that has only a subset of the original columns. And I also want to replace spaces with underscores for one of the columns only. I've tried like this:
gawk -F "," '
{
name=gsub(/ /,"_",$1);
label=$2;
print ","name","label","
}' ./in.csv >> ./out.csv
But gsub() returns the number of match occurences, not the replacement string. So I get something like this:
,1,label
instead of:
,name_nospace,label
How do I use awk gsub like this to replace a character for one column only?
Don't:
as
gsub
returns the number of substitutions, not a string. Justand print the field you fiddled with, ie: