Replace comma with a blank space using SED


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace comma with a blank space using SED
# 1  
Old 01-16-2011
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:
Code:
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:
Code:
name        age, gender, applied, accepted          date

I want it to be like this:
Code:
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:
Code:
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.

Last edited by Scott; 01-16-2011 at 02:22 PM.. Reason: Please use code tags
# 2  
Old 01-16-2011
How about:
Code:
sed -e 's/\'//g' -e 's/,/ /g' inputfile

or you could have:
Code:
sed -e 's/\'//g' inputfile | awk -F, '.....'

This User Gave Thanks to m.d.ludwig For This Post:
# 3  
Old 01-16-2011
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:
Code:
cat test.text | sed -e 's/\'//g

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

Any ideas?

Last edited by Scott; 01-16-2011 at 02:23 PM.. Reason: Code tags, please...
# 4  
Old 01-16-2011
Code:
 sed 's/[`,]//g'

Or combine sed and awk:
Code:
awk -F'[`, ]*' '{print $1,$2,$3}' test.txxt

This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 01-16-2011
Thanks for you help/time, but I was able to figure it out.

I didn't use SED though, I used:

PHP Code:
tr ',' ' ' 
and that did the job.
# 6  
Old 01-21-2011
multiple spaces

Your input shows multiple spaces, do you want just one...
Code:
sed -e 's/\'//g -e 's/,/ /g' -e 's/[ \t]\+/ /g' test.txt

BASH eats the '+' sign so it is escaped.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script using awk to replace space by comma

I have the content of this file that i would like to replace the space by comma. The file content values in this format FName LName Date & time ------------------------------------ Gilles John 14/12/17 12:30:45 I want this format Fname,LName,Date&time... (7 Replies)
Discussion started by: gillesi
7 Replies

2. Shell Programming and Scripting

Replace comma and blank with comma and number

I, I have a file and i need to replace comma and blank space with comma and 0. cat file.txt a,5 b,1 c, d, e,4 I need the output as cat file.txt a,5 b,1 c,0 d,0 (4 Replies)
Discussion started by: jaituteja
4 Replies

3. UNIX for Dummies Questions & Answers

Replace colon with blank space

Dear Gurus, I have a unix file with multiple colons on each row, and I would like to replace each colon with a blank space using the awk command. For example, I have the following data: Data: --------- A~000000000000518000~SLP:~99991231~20090701~00102.00~USD:~CS:~... (2 Replies)
Discussion started by: chumsky
2 Replies

4. Shell Programming and Scripting

sed help - replacing 6th comma with a space

Hi, How can I replace the 6th comma on each line (of a csv) with a space? Any online tutorials with plenty of examples using sed would be very useful. Alex (2 Replies)
Discussion started by: mcclunyboy
2 Replies

5. Shell Programming and Scripting

Replace comma by space for specified field in record

Hi, i want to replace comma by space for specified field in record, i mean i want to replace the commas in the 4th field by space. and rest all is same throught the record. the record is 16458,99,001,"RIMOUSKI, QC",418,"N",7,EST,EDT,902 16458,99,002,"CHANDLER,... (5 Replies)
Discussion started by: raghavendra.cse
5 Replies

6. Shell Programming and Scripting

replace space with comma in perl

arr_Ent_NameId variable holds 'Prakash pawar' 'sag' '23' '50000' this value 'Prakash pawar' 'sag' '23' '50000' I want to replace space( ) with comma (,) There are 4 fields here. I don't want to replace first field with comma. output should be: 'Prakash,pawar','sag','23','50000' ... (2 Replies)
Discussion started by: pritish.sas
2 Replies

7. Shell Programming and Scripting

Removing blank lines from comma seperated and space seperated file.

Hi, I want to remove empty/blank lines from comma seperated and space seperated files Thanks all for help (11 Replies)
Discussion started by: pinnacle
11 Replies

8. Shell Programming and Scripting

How to replace all entries of comma in text file by space or other character

Hi , How to replace all entries of comma in text file by space or other character. cat temp.txt A,B,C,D I want this file to be like A B C D Please help!!! (4 Replies)
Discussion started by: prashant43
4 Replies

9. AIX

How can i replace a character with blank space?

i want a command for my script!!! say file consists of character 123 125 127. i need a query to replace the number 2 with 0 so the output should be 103 105 107. i use unix-aix (8 Replies)
Discussion started by: rollthecoin
8 Replies

10. Shell Programming and Scripting

Replace , (comma) with space

Hi, what is the better way to replace the , (comma) with a space char? Example:STRING=dir1,dir2,dir3 toSTRING=dir1 dir2 dir3 And.. how to find if in the string there is a comma? Thanks :) (6 Replies)
Discussion started by: mbarberis
6 Replies
Login or Register to Ask a Question