aarch1
asked on
help with sed - unix command
I have 100 files looking like this.
<html>
<body>
.....
</body>
</html>
---
I need to add the below line right above the <body> line in each of the above 100 files.
<SCRIPT LANGUAGE='JavaScript'>pare nt.frames. help.locat ion.href = "/sun1/p1?in_p=test";</SCR IPT>
I need a sed script to do this please. I am using kshell in sun solaris unix box.
AMIT G. ALREADY GAVE ME A SOLUTION FOR THE ABOVE.
The solution is
for i in "*.html"
do
sed 's#<body>#<SCRIPT LANGUAGE="JavaScript">pare nt.frames. help.locat ion.href
= "/sun1/p1?in_p=test";</SCR IPT><body> #' $i > /tmp/$i.$$
mv /tmp/$i.$$
done
-------------------------
THE NEW NEED IS,
WHEN THE <BODY> TAG IS IN MIXED CASE THE ABOVE SOLUTION DOES NOT WORK.
Thanks
<html>
<body>
.....
</body>
</html>
---
I need to add the below line right above the <body> line in each of the above 100 files.
<SCRIPT LANGUAGE='JavaScript'>pare
I need a sed script to do this please. I am using kshell in sun solaris unix box.
AMIT G. ALREADY GAVE ME A SOLUTION FOR THE ABOVE.
The solution is
for i in "*.html"
do
sed 's#<body>#<SCRIPT LANGUAGE="JavaScript">pare
= "/sun1/p1?in_p=test";</SCR
mv /tmp/$i.$$
done
-------------------------
THE NEW NEED IS,
WHEN THE <BODY> TAG IS IN MIXED CASE THE ABOVE SOLUTION DOES NOT WORK.
Thanks
ASKER
Hi,
That does not work.
I know a way to fix it.
Below takes care of Body or body.
But then I need to do for each char.
sed 's#<[Bb]ody>#<SCRIPT LANGUAGE="JavaScript">pare nt.frames. help.locat ion.href
= "/sun1/p1?in_p=test";</SCR IPT><body> #' $i > /tmp/$i.$$
Do you know of any other solution?
Thanks
That does not work.
I know a way to fix it.
Below takes care of Body or body.
But then I need to do for each char.
sed 's#<[Bb]ody>#<SCRIPT LANGUAGE="JavaScript">pare
= "/sun1/p1?in_p=test";</SCR
Do you know of any other solution?
Thanks
That should have worked. Adding i after the last # should make the match case-insensitive. Could you try again.
amit,
Give this a try:
sed 's#<\([bB][oO][dD][yY]\)># <SCRIPT LANGUAGE="JavaScript">pare nt.frames. help.
location.href = "/sun1/p1?in_p=test";</SCR IPT><\1>#' $1 > /tmp/$i.$$
Give this a try:
sed 's#<\([bB][oO][dD][yY]\)>#
location.href = "/sun1/p1?in_p=test";</SCR
There is no need to use [bB] expression as i flag is already there for this situation.
Amit,
Oops, instead of the OP I put your name by mistake.
BTW, I tried the i flag but it doesn't work in Solaris. Perhaps you are using some other version of sed like gnu sed?
Oops, instead of the OP I put your name by mistake.
BTW, I tried the i flag but it doesn't work in Solaris. Perhaps you are using some other version of sed like gnu sed?
Oh you are right. I am using gnu sed.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sed 's#<body>#<SCRIPT LANGUAGE="JavaScript">pare
= "/sun1/p1?in_p=test";</SCR
to
sed 's#<body>#<SCRIPT LANGUAGE="JavaScript">pare
= "/sun1/p1?in_p=test";</SCR
You could have asked this as a followup in the previous question itself.