Solved

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

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now