Operating System - HP-UX
1826331 Members
3975 Online
109692 Solutions
New Discussion

sed commands not working on HP-UX. Need help.

 
sree sakamuri
Advisor

sed commands not working on HP-UX. Need help.

Hello Guys

As part of script to strip off the absolute paths attached to the system commands(like rm, cp, grep etc), i used sed to do the job.

The sed commands i used, which are working fine on Linux, aren't working on HP-UX.

1)
sed -e 's#/usr.[^ ]*/\|/sbin.[^ ]*/\|/bin.[^ ]*/##g' $DEST_DIR/$1 > $DEST_DIR/new_$1
mv $DEST_DIR/new_$1 $DEST_DIR/$1

2)
sed -e "1i'$top'" $DEST_DIR/$1 > $DEST_DIR/new_$1
mv $DEST_DIR/new_$1 $DEST_DIR/$1

3)
sed -e '2i\export PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin/' $DEST_DIR/$1 > $DEST_DIR/new_$1
mv $DEST_DIR/new_$1 $DEST_DIR/$1

when the script is run, 1) is not returning any error but simply not doing the job. but 2) and 3) are returning errors as below.

error for 2)
sed: Function 1i'#!/usr/bin/ksh' cannot be parsed.

error for 3)
sed: Function 2i\export PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin/ cannot be parsed.

Please let me know where i am doing it wrong.
Any help is appreciated.

FYI : the actual script is attached.

Regards
8 REPLIES 8
Ralph Grothe
Honored Contributor

Re: sed commands not working on HP-UX. Need help.

Hi Sree,

without having looked at your script,
don't you think you could avoid the sed stuff
by simply making use of the shell's parameter substitution like e.g.?

$ (elog=/var/opt/resmon/log/event.log;echo ${elog##*/})
event.log
Madness, thy name is system administration
sree sakamuri
Advisor

Re: sed commands not working on HP-UX. Need help.

Hello Ralph

Thanks for your reply.

I am not very good in programming. The initial script i wrote worked fine in Linux. But when it comes to HP-UX the issues started.

I am searching all over google and other forums for a workaround on this. But no luck.

Your help is appreciated.

Regards
Steven Schweda
Honored Contributor

Re: sed commands not working on HP-UX. Need help.

Ralph Grothe
Honored Contributor

Re: sed commands not working on HP-UX. Need help.

Having looked in your script
I think to understand what you want to achieve.
It looks as though you want to strip all paths from any executables and instead populate the PATH environment and call them just by their names.
Looks like some sort of porting between Unices with executables with deviating paths.

I have to admit that I'm not quite into sed's syntax (pampered too much by PCREs).

So I could only tell you what a Perl regex could remotely look like to strip the paths.

e.g.

perl -npe 's#/(?:usr|bin|sbin)\S*/##g' $DEST_DIR/$1

Sorry.
Madness, thy name is system administration
sree sakamuri
Advisor

Re: sed commands not working on HP-UX. Need help.

Hello Ralph

You interpreted the script quite right. That is exactly what the script demands.

Fortunately with the help of James, i managed to acheive the results.

Please check this post,
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1421985

Many THnx for your idea in perl, will note it down for future usage. :)

Regards
Steven Schweda
Honored Contributor

Re: sed commands not working on HP-UX. Need help.

> Apr 15, 2010 14:29:32 GMT 0 pts
> http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1421985

> Please check this post,
> http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1421985

So, when I mention it, it's worthless, but
when you suggest it, it's a good idea?
sree sakamuri
Advisor

Re: sed commands not working on HP-UX. Need help.

Hello Steven

I am new to the Forums.

If i offended you in some way, then I am ready to offer an unconditional apology.

My intention was never to mark your reply as "Worthless".

Best Regards
sree sakamuri
Advisor

Re: sed commands not working on HP-UX. Need help.

raised the post in another category and got the solution.