Reputation: 316
eg, each row of the file is like :
1, 2, 3, 4,..., 1000
How can print out
1 2 3 4 ... 1000
?
Upvotes: 2
Views: 8282
Reputation: 247240
You could also remove the field separators:
awk -F, '{gsub(FS,"")} 1'
Upvotes: 3
Reputation: 212674
You need to set OFS (the output field separator). Unfortunately, this has no effect unless you also modify the string, leading the rather cryptic:
awk '{$1=$1}1' FS=, OFS=
Although, if you are happy with some additional space being added, you can leave OFS at its default value (a single space), and do:
awk -F, '{$1=$1}1'
and if you don't mind omitting blank lines in the output, you can simplify further to:
awk -F, '$1=$1'
Upvotes: 6
Reputation: 782785
Set FS
to the input field separators. Assigning to $1
will then reformat the field using the output field separator, which defaults to space:
awk -F',\s*' '{$1 = $1; print}'
See the GNU Awk Manual for an explanation of $1 = $1
Upvotes: 1
Reputation: 290525
If you just want to delete the commas, you can use tr
:
$ tr -d ',' <file
1 2 3 4 1000
If it is something more general, you can set FS
and OFS
(read about FS and OFS) in your begin block:
awk 'BEGIN{FS=","; OFS=""} ...' file
Upvotes: 7