Solved

quick one

Posted on 2009-07-09
4
285 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending email via Perl on Windows 3 167
Port 80 requests 16 96
instmodsh - listing perl modules 2 80
Migrate OTRS to newest version. 1 336
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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 …
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

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