How to replace first space with comma in UNIX

My question: I have 2 columns. The text in the secound column has comma separated values. I want the 2 columns to be uninstalled as comma separated and the comma separated text in the second column should remain as it is.

For example: A, B - column name:

A   B
123 Hi There
234 Hello there

      

I want the result to be

A,B
123,Hi There
234,Hellothere

      

Can anyone help me?

+3


source to share


2 answers


You can use this command sed

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

      

+8


source


Try it sed 's/ /,/' filename.txt

.



+1


source







All Articles