The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > Linux
Google UNIX.COM


Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" iBot UNIX and Linux RSS News 0 01-04-2008 12:00 PM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-19-2007 10:52 PM
No utpmx entry: you must exec "login" from lowest level "shell" peterpan UNIX for Dummies Questions & Answers 0 01-18-2006 01:15 AM
"sed -n expression " fails. Why? grahamb Shell Programming and Scripting 2 12-14-2005 10:44 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 05-29-2008
Registered User
 

Join Date: Mar 2008
Posts: 7
Regular expression to extract "y" from "abc/x.y.z" .... i need regular expression

Regular expression to extract "y" from "abc/x.y.z"
Reply With Quote
Forum Sponsor
  #2  
Old 05-29-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Regular expressions, as such, only "match", they don't "extract". Some scripting languages have a facility for returning the part of a regular expression which matched, but it then depends on which language you want.

Without more information about what to look for precisely, the simple answer is that the regular expression "y" will match the letter "y", and the matching (extracted) string will always be "y".

If you want the first substring between two periods, that's something like this:

Code:
sed -n 's/.*\.\([^.]*\)\..*/\1/p' file
or with Perl:

Code:
perl -lne 'if (m/\.([^.]*)\./) { print $1 }' file
or with awk:

Code:
awk -F . '{ print $2 }' file
The latter doesn't use regular expressions at all, though.

But really, you need to explain in more detail what the parameters of the problem are.

Last edited by era; 05-29-2008 at 12:30 AM. Reason: Add Perl example
Reply With Quote
  #3  
Old 05-29-2008
Registered User
 

Join Date: Apr 2008
Location: Bangalore
Posts: 123
Hi,

sed 's/.*\.\(.*\)\..*/\1/'

using cut :

cut -d"." -f2

Thanks
Penchal
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
regex, regular expressions

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0