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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk: need to extract a line before a pattern npn35 Shell Programming and Scripting 17 06-29-2008 07:38 PM
extract a particular start and end pattern from a line manish205 Shell Programming and Scripting 7 02-07-2008 03:18 AM
Extract Pattern Sequence jaganadh Shell Programming and Scripting 5 12-10-2007 08:06 AM
Extract if pattern matches Raynon Shell Programming and Scripting 20 10-29-2007 01:44 AM
Extract the Pattern aajan UNIX for Dummies Questions & Answers 6 08-08-2007 01:47 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-14-2006
Registered User
 

Join Date: Sep 2006
Posts: 3
Please help! Sed extract a pattern

I am trying to extract "securitySettings" out of line:

<a ref ="http://localhost:5654/securitySettings">

using sed as follows:

name = `grep "localhost" file.html | sed -n 's/.*[0-9]*\/\(.*)/\">/\1/p'`

But it didn’t run, seems have some syntax error. Do anybody knows why?

Thank you very much!
Reply With Quote
Forum Sponsor
  #2  
Old 09-14-2006
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
you missed \ in \(.*\)
unnecessary / in /\">/\1/p
after those modifications
Code:
sed -n 's/.*[0-9]*\/\(.*\)">/\1/p'

Last edited by anbu23; 09-14-2006 at 02:20 PM.
Reply With Quote
  #3  
Old 09-14-2006
Registered User
 

Join Date: Jul 2006
Posts: 73
emmmm, why this did not work? it has a ">" at the end of output

$ sed 's/^.*:[0-9][0-9]*\/\([^\"]*\)\"\>/\1/' /tmp/test
securitySettings>
Reply With Quote
  #4  
Old 09-14-2006
reborg's Avatar
Administrator
 

Join Date: Mar 2005
Location: Ireland
Posts: 3,638
Code:
sed -n 's_.*/\([^/]*\)">_\1_p'
Reply With Quote
  #5  
Old 09-14-2006
Registered User
 

Join Date: Aug 2006
Posts: 30
Arrow way simpler

can be don in a much more simpler way as follows(i mean there is lesser chance of getting lost in sed )
Code:
grep "loaclhost" file.html | awk -F'/' '{print $NF }' | sed -e 's/>//g'
hope his works.........do let us know
Reply With Quote
  #6  
Old 09-15-2006
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Quote:
Originally Posted by zhen
I am trying to extract "securitySettings" out of line:

<a ref ="http://localhost:5654/securitySettings">

using sed as follows:

name = `grep "localhost" file.html | sed -n 's/.*[0-9]*\/\(.*)/\">/\1/p'`

But it didn’t run, seems have some syntax error. Do anybody knows why?

Thank you very much!
hi , can i clarify , you just want to get "securitySettings" from a line and then assign the value "securitySettings" to a variable called "name" ?

Code:
grep "securitySettings" file.html
if [ $? -eq 0 ]; then
   name='securitySettings'
fi
I think i am missing something...
Reply With Quote
  #7  
Old 09-15-2006
Registered User
 

Join Date: Aug 2006
Posts: 30
Quote:
Originally Posted by ghostdog74
hi , can i clarify , you just want to get "securitySettings" from a line and then assign the value "securitySettings" to a variable called "name" ?

I think i am missing something...
he doesnt want to search for securitySettings. Instead he wants to search the word "localhost" and find the last part of that link(href as in a html tag)...
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:55 PM.


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