Stewart Anderson wrote:
JC Janos wrote:

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.

Here  is an example of the same thing in shell speak just do whatever
you want with.  The  ipaddy  in the loop  to purduce the  string you
require.


cat ipin.txt |while read inline do ipaddy=`echo $inline |awk '{print $1 } '` echo $ipaddy done

Why not just:

ipaddy=`awk '{ print $1 }' ipin.txt`


But that still doesn't get you a comma-separated list.



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/


Reply via email to