JC Janos wrote:
Hi,
Hello,
I have a file containing IP addresses & ranges, their negations, and
comments. E.g.,
1.1.1.1 # comment A
2.2.2.2/29 # comment B
!3.3.3.3 # comment C
!4.4.4.4/28 # comment D
I need to extract those IPs & ranges, rearrange them into a
comma-separated list, e.g.,
1.1.1.1,2.2.2/29,!3.3.3.3,!4.4.4.4/28
I've read that Perl (which I don't know yet at all) is "best" for Text
processing like this.
The thing is that I need to do this from within a Bash script, and
assign the comma-separated list to a variable in that Bash script.
$ echo $TEST
$ cat yourfile.txt
1.1.1.1 # comment A
2.2.2.2/29 # comment B
!3.3.3.3 # comment C
!4.4.4.4/28 # comment D
$ TEST=$(perl -lp0777e'$_=join",",/!?[\d.]+(?:\/\d+)?/g' yourfile.txt);
echo $TEST
1.1.1.1,2.2.2.2/29,!3.3.3.3,!4.4.4.4/28
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/