Replace comma with a blank space using SED

Hello everyone,

I want to replace all "," (commas) with a blank space

My command thus far is:

cat test.text | sed -e s/\`//g | awk '{print$1"  "$2"  "$3}'

I'm sure you guys know this, but the SED command that I am using is to get rid of the "`" (tics).

which gives me:

name        age, gender, applied, accepted          date

I want it to be like this:

name      age     gender     applied     accepted     date

So when I use the awk command, "$1" = name, "$2" = age, "$3"=gender, etc. instead of "$1"=name, "$2"=age, gender, applied, accepted, and "$4"=date

Without my current use of SED in my command my outout looks like this:

name        `age`, `gender`, `applied`, `accepted`          date

So if there is a way to accomplish both with one SED command that would be neat.

Thank you to anyone can help me out.

How about:

sed -e 's/\'//g' -e 's/,/ /g' inputfile

or you could have:

sed -e 's/\'//g' inputfile | awk -F, '.....'
1 Like

Thanks for the quick reply, however I couldn't get either of those to work. But I wouldn't rule out user error on this. Perhaps I'm improperly placing the SED command?

I did it like this:

cat test.text | sed -e 's/\'//g

i left out my other sed command and awk commands just to see if worked.

Any ideas?

 sed 's/[`,]//g' 

Or combine sed and awk:

awk -F'[`, ]*' '{print $1,$2,$3}' test.txxt
1 Like

Thanks for you help/time, but I was able to figure it out.

I didn't use SED though, I used:

tr ',' ' '

and that did the job.

Your input shows multiple spaces, do you want just one...

sed -e 's/\'//g -e 's/,/ /g' -e 's/[ \t]\+/ /g' test.txt

BASH eats the '+' sign so it is escaped.