Solved

help with sed - unix  command

Posted on 2007-04-04
10
849 Views
Last Modified: 2013-12-26
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'>parent.frames.help.location.href = "/sun1/p1?in_p=test";</SCRIPT>

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">parent.frames.help.location.href
= "/sun1/p1?in_p=test";</SCRIPT><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
0
Comment
Question by:aarch1
10 Comments
 
LVL 58

Expert Comment

by:amit_g
ID: 18853113
Change

sed 's#<body>#<SCRIPT LANGUAGE="JavaScript">parent.frames.help.location.href
= "/sun1/p1?in_p=test";</SCRIPT><body>#' $i > /tmp/$i.$$

to

sed 's#<body>#<SCRIPT LANGUAGE="JavaScript">parent.frames.help.location.href
= "/sun1/p1?in_p=test";</SCRIPT><body>#i' $i > /tmp/$i.$$

You could have asked this as a followup in the previous question itself.
0
 

Author Comment

by:aarch1
ID: 18853354
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">parent.frames.help.location.href
= "/sun1/p1?in_p=test";</SCRIPT><body>#' $i > /tmp/$i.$$

Do you know of any other solution?



Thanks
0
 
LVL 58

Expert Comment

by:amit_g
ID: 18853371
That should have worked. Adding i after the last # should make the match case-insensitive. Could you try again.
0
 
LVL 7

Expert Comment

by:nixfreak
ID: 18859028
amit,

Give this a try:

sed 's#<\([bB][oO][dD][yY]\)>#<SCRIPT LANGUAGE="JavaScript">parent.frames.help.
location.href = "/sun1/p1?in_p=test";</SCRIPT><\1>#' $1 > /tmp/$i.$$
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 58

Expert Comment

by:amit_g
ID: 18859525
There is no need to use [bB] expression as i flag is already there for this situation.
0
 
LVL 7

Expert Comment

by:nixfreak
ID: 18860640
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?

0
 
LVL 58

Expert Comment

by:amit_g
ID: 18860687
Oh you are right. I am using gnu sed.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 22505743
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now