Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

help with sed - unix  command

Posted on 2007-04-04
10
Medium Priority
?
873 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

610 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