Solved

quick awk/sed question: how to add characters in a line

Posted on 2014-02-11
2
346 Views
Last Modified: 2014-02-11
Have many long lines like the following:

(AA 10, (xxx-xx-xxx) BB, 200 A)
(Test 20, (YYY-YY-YYY) DCB, 100000 BBB)
....

How to add a comma to the positions which do not have?
Expected output is
(AA, 10, (xxx-xx-xxx), BB, 200, A)
(Test, 20, (YYY-YY-YYY), DCB, 100000, BBB)
...

Preferred awk/sed, but perl is OK too.
Thanks in advance.
0
Comment
Question by:jl66
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 39850704
sed 's/\([^ ,]\) /\1, /g'  <<END
(AA 10, (xxx-xx-xxx) BB, 200 A)
(Test 20, (YYY-YY-YYY) DCB, 100000 BBB)
END
0
 

Author Closing Comment

by:jl66
ID: 39851005
ozo, you have always been helpful. I really appreciate.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
The viewer will learn how to dynamically set the form action using jQuery.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question