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?
The command s/,/ /g tells sed to replace every comma with a space. q tells it to quit after the first line. The lone < indicates redirection: it tells the shell to get its input for the read command from the file-like object that follows on the command line.
Simple SED commands are: sed s/ */ /g This will replace any number of spaces with a single space. sed s/ $// This will replace any single space at the end of the line with nothing. sed s/ /,/g This will replace any single space with a single comma.
sed 's/,/ /g' filename >resultfile
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With