The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Awk regular expressions chella Shell Programming and Scripting 1 03-30-2009 07:32 AM
How to extract text from string using regular expressions jtung Shell Programming and Scripting 9 10-17-2008 08:51 PM
Regular Expressions ramky79 UNIX for Advanced & Expert Users 3 05-21-2008 06:13 PM
regular expressions jack1981 Shell Programming and Scripting 4 07-12-2006 04:10 PM
Regular Expressions AresMedia Shell Programming and Scripting 1 08-22-2002 04:55 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-18-2009
akatraga akatraga is offline
Registered User
  
 

Join Date: May 2009
Posts: 1
Question Need help in string extraction using regular expressions

Hi, I am a new bee to this forum.

I am trying to extract the text after a matching pattern from a url using regular expression.

Ex:
Code:
http://locatlhost:2020/proxy/checkthisout

I want to extract the string after proxy/. I am not familiar with reg ex. Can someone please help?

Last edited by Franklin52; 05-18-2009 at 04:13 PM.. Reason: Replace url tags
  #2 (permalink)  
Old 05-25-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,893
Quote:
I am a new bee ... I want to extract the string
Do you want to extract the string or the sting?

man sed

You probably want something like:

Code:
sed -n 's/.*http:\/\/localhost:3030\/proxy\///p'

  #3 (permalink)  
Old 05-25-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 552
Quote:
Originally Posted by akatraga View Post
...
I am trying to extract the text after a matching pattern from a url using regular expression.
Ex:
Code:
http://locatlhost:2020/proxy/checkthisout

...
You can use regular expressions with more than one command.

Using plain old bash shell:


Code:
$
$ URL="http://localhost:2020/proxy/checkthisout"
$
$ echo ${URL##*/}
checkthisout
$
$ echo `expr "$URL" : '.*/\(.*$\)'`
checkthisout
$

Using perl:


Code:
$
$ echo "http://locatlhost:2020/proxy/checkthisout" | perl -ne 's#.*/##; print'
checkthisout
$

Using awk:


Code:
$
$ echo "http://locatlhost:2020/proxy/checkthisout" | awk 'sub(/.*\//,"")'
checkthisout
$

tyler_durden
Closed Thread

Bookmarks

Tags
regex, url

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:16 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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