1

I found an answer on how to remove commas between quotes of a comma delimited csv file over here on stackexchange (cannot comment there as I don't have the needed rep).

awk -F'"' -v OFS='' '{ for (i=2; i<=NF; i+=2) gsub(",", "", $i) } 1' infile

How can I redirect the output to a file instead of printing it to the console?

I tried various combinations of using '>' which only gave me empty files or errors. '>>' gave me an error every time.

1 Answers1

2

Using the standard redirect will work on standard out:

$ awk -F'"' -v OFS='' '{ for (i=2; i<=NF; i+=2) gsub(",", "", $i) } 1' infile > test.out
$

This will still print errors to the screen.

However, if you want errors and standard out to go into the file then run:

$ awk -F'"' -v OFS='' '{ for (i=2; i<=NF; i+=2) gsub(",", "", $i) } 1' infile 2>&1 > test.out
$

Or you can seperate the errors from the standard output:

awk -F'"' -v OFS='' '{ for (i=2; i<=NF; i+=2) gsub(",", "", $i) } 1' infile 2> errors.out 1 > test.out
geedoubleya
  • 4,327