Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 Jan 2008 10:34:05 -0700 (MST)
From:      fbsdq@peterk.org
To:        "Paul Schmehl" <pauls@utdallas.edu>
Cc:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Re: Shell scripting kungfu
Message-ID:  <1354.63.65.46.186.1200677645.squirrel@webmail.pknet.net>

next in thread | raw e-mail | index | archive | help
> I need to do the following:
>
> Take a list of various strings, one of which is a quoted IP address, and
> extract the IPs.  (Done that.)
>
> Then take the list of IPs and convert them to a list of IPs with masks on
> a
> single line.
>
> IOW, I have converted the original list to this:
>
> x.x.x.x
> x.x.x.x
> x.x.x.x
> x.x.x.x
>
> Now I need to remove the newlines and add /32, to the end of each IP so
> that I
> have this:
> x.x.x.x/32,x.x.x.x/32,x.x.x.x/32,etc.
>
> I got close with sed, but I'm not quite there.
>
> I got this:
>
> x.x.x.x/32,x.x.x.x
> x.x.x.x/32,x.x.x.x
> x.x.x.x/32,x.x.x.x
>
> Here's the code I used:
> cat hostlist | cut -d',' -f2 | cut -d'"' -f2 | sort | uniq | grep -v
> "inet" |
> sed '/[^*]$/N;s/\n */\/32,/'
>
> What am I missing?
 you are missing 'tr' I guess;

chernogorsk:#cat /tmp/x
x.x.x.x
x.x.x.x
x.x.x.x
x.x.x.x
chernogorsk:#cat /tmp/x | sed 's/$/\/32,/g'|tr -d "\r\n" > /tmp/x2; echo
>> /tmp/x2
chernogorsk:#cat /tmp/x2
x.x.x.x/32,x.x.x.x/32,x.x.x.x/32,x.x.x.x/32,

some fine tunning and getting rid of the trailing ',' you can add another
sed pipe, etc.etc.

]Peter[


>

>

>
> --
> Paul Schmehl (pauls@utdallas.edu)
> Senior Information Security Analyst
> The University of Texas at Dallas
> http://www.utdallas.edu/ir/security/
>
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to
> "freebsd-questions-unsubscribe@freebsd.org"
>





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1354.63.65.46.186.1200677645.squirrel>