18

I'm looking for a Unix command that will allow me to search/replace in a file - I need to replace all commas in a certain file with spaces. I need to do this in a script and I'm looking to avoid parsing/reading the file line by line. Is there a simple unix command that will allow me to do this?

Amir Rachum
  • 76,817
  • 74
  • 166
  • 248

3 Answers3

26

sed 's/,/ /g' filename >resultfile

khachik
  • 28,112
  • 9
  • 59
  • 94
7

You can use awk, sed, vi, ex or even Perl, PHP etc ... depends what you are proficient with.

sed example:

sed -i 's/,/ /g' filename_here
Konerak
  • 39,272
  • 12
  • 98
  • 118
0

I would suggest awk, in case you also need to expand your command with some conditionals (take a look here)

awk '{gsub(",", " "); print}' file_path > resultfile_path
Tms91
  • 3,456
  • 6
  • 40
  • 74