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 > 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: need to extract a line before a pattern npn35 Shell Programming and Scripting 17 06-29-2008 10:38 PM
extract a particular start and end pattern from a line manish205 Shell Programming and Scripting 7 02-07-2008 06:18 AM
Extract Pattern Sequence jaganadh Shell Programming and Scripting 5 12-10-2007 11:06 AM
Extract if pattern matches Raynon Shell Programming and Scripting 20 10-29-2007 04:44 AM
Extract the Pattern aajan UNIX for Dummies Questions & Answers 6 08-08-2007 04:47 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-14-2006
zhen zhen is offline
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!
  #2 (permalink)  
Old 09-14-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
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 05:20 PM..
  #3 (permalink)  
Old 09-14-2006
fedora fedora is offline
Registered User
  
 

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

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

Join Date: Mar 2005
Location: Ireland
Posts: 4,209
Code:
sed -n 's_.*/\([^/]*\)">_\1_p'
  #5 (permalink)  
Old 09-15-2006
sayonm sayonm is offline
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
  #6 (permalink)  
Old 09-15-2006
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
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...
  #7 (permalink)  
Old 09-15-2006
sayonm sayonm is offline
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)...
Closed Thread

Bookmarks

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 11:37 PM.


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