Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I replace first space with comma in UNIX

Tags:

unix

My Question is, I have 2 columns. The text in the secound column has comma seperated values. I want the 2 columns to be deisplayed as comma seperated and the comma seperated text in 2nd column should remain as it is.

E.g: A,B being the name of the columns:

A   B
123 Hi There
234 Hello there

I want the output as

A,B
123,Hi There
234,Hellothere

Can someone please help me?

like image 539
user80040 Avatar asked Nov 04 '14 12:11

user80040


1 Answers

You can use this sed command

sed -r 's/\s+/,/' File_Name

or

sed -r 's/ +/,/' File_Name


 -r, --regexp-extended

          use extended regular expressions in the script.

Output :

A,B
123,Hi There
234,Hello there
like image 177
Kalanidhi Avatar answered Sep 20 '22 23:09

Kalanidhi