How to Use Sed Command to replace white spaces with comma from between two fields - Mayank

SHELL SCRIPT

Hi
I have a file in the following format
Mayank Sushant
Dheeraj Kunal
ARUN Samir

How can i replace the white space in between and replace them with a comma?? The resultant output should be
Mayank,Sushant
Dheeraj,Kunal
ARUN,Samir

i tried using
sed -e "s/[ ^I]/,/g"
and
sed -e "s/[ ^I]*/,/g"

Hi
If it is single space, this should do for you:

sed 's/ /,/'  file

Guru

Try even if more than one space...

 
sed 's/\( \)\{1,\}/,/g' infile

Hi Guru

Actually i took output of a MySql query (the result had 2 columns) into a file. There is white space between the values of two separate columns.

I tried saving it as a CSV file but it did not work. And the sed command u have given or the ones i have tried do not work either.

---------- Post updated at 04:42 PM ---------- Previous update was at 04:39 PM ----------

Hi,

The data within the file is like :

2000020354 Testing
2000020351 Sagar
2000020342 Hello
2000020334 asdsadsda
2000020329 Hello
2000020328 samir
2000020328 sameer

Its not multiple spaces but a single tab. and yet no sed command is working. Is it due to the reason that i saveed the result from a Mysql Query??

have you tried this?

sed 's/\( \)\{1,\}/,/g' infile

hey Malcomex999, Yes I did try this but did not work...

Assuming you are having two columns only...

 
awk 'NF{print $1","$2}' infile

great this works just fine. I am new to shell so havent started using awk and CURL. can u suggest me a few e-tutorials for awk

What I suggest you is that to stick and search this forum where you can find everything including the link for tutorials.

Good luck!:b: