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!

you missed \ in \(.*\)
unnecessary / in /\">/\1/p
after those modifications

sed -n 's/.*[0-9]*\/\(.*\)">/\1/p'

emmmm, why this did not work? it has a ">" at the end of output :confused: :confused:

$ sed 's/^.*:[0-9][0-9]*\/\([^\"]*\)\"\>/\1/' /tmp/test
securitySettings>

sed -n 's_.*/\([^/]*\)">_\1_p'

can be don in a much more simpler way as follows(i mean there is lesser chance of getting lost in sed :slight_smile: )

grep "loaclhost" file.html | awk -F'/' '{print $NF }' | sed -e 's/>//g'

hope his works.........do let us know

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

grep "securitySettings" file.html
if [ $? -eq 0 ]; then
   name='securitySettings'
fi

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

oic, thanks :slight_smile:

Thank you guys, I finally got this by doing

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

but if I have multiple launchpoints in the html file, like this:

< a href ="http://localhost:5645/securitySettings">
< a href ="http://localhost:5645/security">
< a href ="http://localhost:5645/test">

Then, the name varible will include those three patterns( securitySettings, security, test), and I will get extra pattern when apply the name varible to the change_lines functions. Is there anyway I can get one pattern at a time? My code looks like this:

NAME=\`grep "localhost" $FILE | sed -n 's/.\*:[0-9]\*\\/\\\(.*\\\)\\"&gt;/\\1/p'\`

echo ""
echo "NAME=$NAME"
echo ""

change_lines $FILE "localhost" "&lt;a href= \\"javascript:top.launchFacility\('$\{NAME\}'\)\\"&gt;"

Thanks again^^

for str in $NAME
do
change_lines $FILE "localhost" "<a href= \"javascript:top.launchFacility('${str}')\">"
done

Got it, Thank everyone for your help.

You can do all the work without using grep :

name =`NAME=`sed -n 's/.*localhost:[0-9]*\/\(.*\)\">/\1/p'` $FILE

Jean-Pierre.