Solved

quick one

Posted on 2009-07-09
4
296 Views
Last Modified: 2012-05-07
I have a file with a sequence of hex numbers, one per line. I need to get them all on one line, comma delimited. I can get the comma on the end, but how do I join up all my little scalars into an array and print?

So far I have  perl -wnl -e 's/$/,/g;print' my-devs which gives me

0001,
0002,
etc...

I want 0001,0002

thanks.
0
Comment
Question by:Rowley
4 Comments
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24813711
Try this?

perl -wnl -e 's/[\n\r]+/,/gm;print'
0
 
LVL 39

Accepted Solution

by:
Adam314 earned 125 total points
ID: 24814102
On windows, replace single quote ' with double quote "

#If you already have the comma's, and just need to join the lines:
perl -pe 'chomp' file.txt
 
#If you need to add comma's and join the lines:
perl -pe 's/[\r\n]+/,/' file.txt

Open in new window

0
 
LVL 13

Author Closing Comment

by:Rowley
ID: 31601591
spot on ta. -p - handy too. Other poster - sorry, didn't work.
0
 
LVL 84

Expert Comment

by:ozo
ID: 24814466
perl -wpl -e '$\=!s/$/,/;' my-devs
0

Featured Post

Independent Software Vendors: 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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
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…

685 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