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?
Asked
Active
Viewed 4.4k times
3 Answers
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
-
I'm using vi, but I need to do it in a script. Thanks. – Amir Rachum Mar 29 '11 at 08:23
-
1If you're a vi adept, consider the commandline `ex` version which allows the same commands: `%s/,/ /g` would work. You can do this in a script, too. – Konerak Mar 29 '11 at 09:19
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