1833137 Members
3771 Online
110051 Solutions
New Discussion

Re: sed ????

 
SOLVED
Go to solution
Nabil_2
Advisor

sed ????

sed ??? ( post #1)

Hello,

I am working on a project that require migration of a lot of scripts from an SGI IRIX to an HP-UX environment. These scripts may have a lot of statements that include "rsh" or other IRIX specific PATH statements.

I would like to automate this migration as much as possible for example using sed to replace the word"rsh" with HP-UX "remsh".

Can any one suggest a scripts that can do this change for me.

Any help will be greatly appreciated.


Thanks.

12 REPLIES 12
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: sed ????

Well, you can use sed but that means you have to keep up with making temp files, preserving permissions, and then mv'ing the temp file to the original. An easier way is to use Perl with the -i argument to create a backup and the -p argument to loop over the files.

perl -p -i.bkup -e 's/rsh/remsh/g' file1 file2 ...

Believe it or not, you are done and you have file1.bkup file2.bkup as well. If you leave off the .bkup (just use -i) then no backup will be created.
If it ain't broke, I can fix that.
steven Burgess_2
Honored Contributor

Re: sed ????

Hi

using sed from the command line

sed s/rsh/remsh/g

will replace rsh with remsh in

Regards

Steve
take your time and think things through
steven Burgess_2
Honored Contributor

Re: sed ????

Hi

To action this on a number of files in a directory

#!/usr/bin/sh

for file in *
do cat $file | sed s/rsh/remsh/g > newfile
cp newfile $file
done

Regards

Steve

take your time and think things through
Nabil_2
Advisor

Re: sed ????

Thank you both for replying.
I do like both solutions athough I really did not need to make any backup copies of original files in the perl example but I like the other shell sed solution...It worked for me....

I think I will go with that.

Thank you all very much.

A. Clay Stephenson
Acclaimed Contributor

Re: sed ????

That's fine but I assume that if you simply

perl -p -i -e 's/rsh/remsh/g' *

Then every file in the directory is done AND permissions/modes are preserved.










If it ain't broke, I can fix that.
Nabil_2
Advisor

Re: sed ????

Oops..
Sorry Guys,..I really don't mean to take the easy way out but I am not really scripting guru kind of guy ..

This gave me another idea that I need to take care of also...

Same thing except

checking a certain custom host file and doing remote shell

server1
server2
server3
etc..

to that host then updating .rhost file from a certain host1 to host2...

Please don't take this as me being lazy to learn scripting.. I really need this done by tomorrow....

steven Burgess_2
Honored Contributor

Re: sed ????

Nabil

You can assign points for the answers that have helped you as a token of appreciation


Regards

Steve
take your time and think things through
Nabil_2
Advisor

Re: sed ????

steven,
Please forgive me .. I did not mean to un appreciative ..
Everything posted here for me was very very helpful ..
Thank you for your help ...
Really ...




steven Burgess_2
Honored Contributor

Re: sed ????

Hi

To perform tasks on multiple hosts

for eg - to list resolv.conf file on a number of hosts - presuming you have .rhosts setup

Have a file containing the hostnames /tmp/hostnames

#!/usr/bin/sh

LOG=/tmp/resolv.log
HOSTS=/tmp/hostnames

for file in $(cat $HOSTS)
do
echo $file >> $LOG
remsh $file -n 'll /etc/resolv.conf' >> $LOG 2>&1
done

Manipulate the above to do what you like

Regards

Steve
take your time and think things through
Nabil_2
Advisor

Re: sed ????

Assigning points..Sorry I misunderstood...

Now I know..I just went head and did..

Joseph A Benaiah_1
Regular Advisor

Re: sed ????

Nabil,

I like Clay's use of the perl syntax.

You can also use ed rather than sed:

ed filename << EOF
g/rsh/s/rsh/remsh/
w
q
EOF

Cheers,

Joseph.
Nabil_2
Advisor

Re: sed ????

Hi,
Sorry I did not get back for feedback soon...I have been kind of busy...

Just a feedback ..I have used Clay's method ..It worked really welll ...
Thanks Clay for the help and thank you all for your contributions...