Hi Jim echo $str | perl -pe 's/.*?(\d+\.[\d.]+).*/$1/'
Giving desired result, but i wonder what is use of ? in this expression On Tue, May 24, 2011 at 11:59 AM, Jim Gibson <jimsgib...@gmail.com> wrote: > 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/' > > -- http://linuxmantra.com