Solved

help with sed - unix  command

Posted on 2007-04-04
10
865 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 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