The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > 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 03:00 PM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 01:52 AM
No utpmx entry: you must exec "login" from lowest level "shell" peterpan UNIX for Dummies Questions & Answers 0 01-18-2006 04:15 AM
"sed -n expression " fails. Why? grahamb Shell Programming and Scripting 2 12-14-2005 01:44 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-29-2008
rag84dec rag84dec is offline
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"
  #2 (permalink)  
Old 05-29-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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 03:30 AM.. Reason: Add Perl example
  #3 (permalink)  
Old 05-29-2008
penchal_boddu penchal_boddu is offline
Registered User
  
 

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

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

using cut :

cut -d"." -f2

Thanks
Penchal
Sponsored Links
Closed Thread

Bookmarks

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:39 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0