Solved

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

Posted on 2014-02-11
2
352 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

821 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