FAQ

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/'

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 8 | next ›
Discussion Overview
groupbeginners @
categoriesperl
postedMay 24, '11 at 4:11a
activeMay 27, '11 at 12:26p
posts8
users4
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase