This produces the desired output for the input you showed:
perl -ple '$_=join",",/\d+/g' input.txt
But seriously, it seems like you're not telling us the whole story. Not only does this sound like homework, but your example input & output or specification don't indicate:
- whether there can be lines without any of the target characters, and if yes, where they can appear,
- whether there can be any other characters other than the ones you showed on each line, and if yes, where they can appear,
- what happens if the things between the target characters aren't numbers,
- why you said "extract all numbers" but your existing regex appears to only want a specific number of digits.
- There's probably a couple more questions that I'm not thinking of at the moment.
- Update: Are there always three numbers on the line following the single line?
Technically, my example above solves the problem you posed, so if you want a regex that really works for you, you'll have to be a lot more specific.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.