zhen
September 14, 2006, 4:43pm
1
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!
anbu23
September 14, 2006, 5:03pm
2
you missed \ in \(.*\)
unnecessary / in /\">/\1/p
after those modifications
sed -n 's/.*[0-9]*\/\(.*\)">/\1/p'
fedora
September 14, 2006, 5:13pm
3
emmmm, why this did not work? it has a ">" at the end of output
$ sed 's/^.*:[0-9][0-9]*\/\([^\"]*\)\"\>/\1/' /tmp/test
securitySettings>
reborg
September 14, 2006, 6:32pm
4
sed -n 's_.*/\([^/]*\)">_\1_p'
sayonm
September 15, 2006, 1:48am
5
can be don in a much more simpler way as follows(i mean there is lesser chance of getting lost in sed )
grep "loaclhost" file.html | awk -F'/' '{print $NF }' | sed -e 's/>//g'
hope his works.........do let us know
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" ?
grep "securitySettings" file.html
if [ $? -eq 0 ]; then
name='securitySettings'
fi
I think i am missing something...
sayonm
September 15, 2006, 6:21am
7
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)...
zhen
September 15, 2006, 10:20am
9
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]\*\\/\\\(.*\\\)\\">/\\1/p'\`
echo ""
echo "NAME=$NAME"
echo ""
change_lines $FILE "localhost" "<a href= \\"javascript:top.launchFacility\('$\{NAME\}'\)\\">"
Thanks again^^
anbu23
September 15, 2006, 10:53am
10
for str in $NAME
do
change_lines $FILE "localhost" "<a href= \"javascript:top.launchFacility('${str}')\">"
done
zhen
September 18, 2006, 10:49am
11
Got it, Thank everyone for your help.
aigles
September 18, 2006, 12:36pm
12
You can do all the work without using grep :
name =`NAME=`sed -n 's/.*localhost:[0-9]*\/\(.*\)\">/\1/p'` $FILE
Jean-Pierre.