Re: shell equivalent to Perl $& op?

From: rakesh sharma (sharma__r_at_hotmail.com)
Date: 04/17/04


Date: 16 Apr 2004 22:11:05 -0700

Gerald Jones wrote in message news:

>
> I am trying to extract all IP addresses from a file. I have access to the
> shell, grep, awk and sed but not perl -- which is how I'd normally do it, like:
>
>
> $ perl -ne '/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/ && echo "$&\n"'
>
> sooooooooooooooooooo.... anyone know how to do it with sed/awk/grep/something
> else in the standard unix toolchest ...?
>

sed -e '
   /\<[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\>/s//\
&\
/;s/.*\n\(.*\)\n.*/\1/p;d
' yourfile



Relevant Pages

  • Re: The existence of God and how we know about Him
    ... "Graham Nye" wrote in message news: ... are his views, from his website, not an extract from a peer-reviewed ... So not much of a 'reference' work then? ...
    (uk.religion.christian)
  • Re: shell equivalent to Perl $& op?
    ... Gerald Jones wrote: ... > I am trying to extract all IP addresses from a file. ... man grep ... Linux solution/training/migration, Thin-client ...
    (comp.unix.shell)