Solved

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

Posted on 2014-02-11
2
358 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
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…
The viewer will learn how to count occurrences of each item in an array.

717 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