At 9:41 AM +0530 5/24/11, vishesh kumar wrote:
Hi Members,

  I am a linux system admin. I want to use perl as a command line like sed
and awk.
For example suppose , i need to extract IP Addr from a string or file using
regrex
i mean
  str="hello ip is 192.168.2.1 and data is xxx"
And i want ip addr only using Regex
 echo $str | perl -pe  ??????

Try this:

  echo $str  | perl -pe 's/[^\d.]//g'

If your line has other numbers, this will get the first contiguous set:

  echo $str | perl -pe 's/.*?([\d.]+).*/$1/'

This will make sure there is at least one dot in the substring extracted:

echo $str | perl -pe 's/.*?(\d+\.[\d.]+).*/$1/'


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to