Operating System - HP-UX
1752786 Members
6219 Online
108789 Solutions
New Discussion юеВ

Re: sed substitution using reg exp commands not working on HP-UX. Need help.

 
SOLVED
Go to solution
sree sakamuri
Advisor

Re: sed substitution using reg exp commands not working on HP-UX. Need help.

Hello James

It certainely doesn't mean your suggestion didn't work. the whole point of 2) was , when stripping off the abs paths from the script, the code shouldn't touch the header (like #!/usr/bin/ksh). I was using something complex like grepping the header into a variable and then deletign it only to be inserted again at the top from the variable content. But in HP-UX was facing problem doing the same.

But found a workaround, simple one liner, where we can make the sed to ignore a particular line when substituting.

like,
1!s/oldline/newline/g

so used it.


The answer about using GNU sed was for steven.

Sorry to confuse you.

Regards
sree sakamuri
Advisor

Re: sed substitution using reg exp commands not working on HP-UX. Need help.

Hello James

I tried your change and below is the code executing in debug mode. It truncated the whole file with a single line in it. pls check the below update.

echo $DEST_DIR/$1 | sed -e '2i\
'"export PATH=\$PATH:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin/" > $DEST_DIR/new_$1
+ sed -e 2i\
export PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin/
+ echo /u08/iBS/release/new_scripts_sree/test_file.sh
+ 1> /u08/iBS/release/new_scripts_sree/new_test_file.sh
mv $DEST_DIR/new_$1 $DEST_DIR/$1
+ mv /u08/iBS/release/new_scripts_sree/new_test_file.sh /u08/iBS/release/new_scripts_sree/test_file.sh

$ cat test_file.sh
/u08/iBS/release/new_scripts_sree/test_file.sh
$


Regards
sree sakamuri
Advisor

Re: sed substitution using reg exp commands not working on HP-UX. Need help.

Hello James.

I made a small change to your code and it worked. :)

Thanks a lot.

the code i used,

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


I appreciate all your help.

Best Regards & THanks
Steven Schweda
Honored Contributor

Re: sed substitution using reg exp commands not working on HP-UX. Need help.

> The answer about using GNU sed was for steven.
>
> Sorry to confuse you.

It confused me, too.

My point was that if you want a "sed" on an
HP-UX system to work exactly like the (GNU)
"sed" on a GNU/Linux system, then it might
make some sense to use GNU "sed" on the HP-UX
system.

> Yes, I followed GNU sed.

I don't know what that means.
sree sakamuri
Advisor

Re: sed substitution using reg exp commands not working on HP-UX. Need help.

Hi Steven

Now i understand exactly what you mean.

Thanks for clarifying. Yes. THat is a important point to note. Can you kindly let me know how to make sure that both Linux and HP-UX are using GNU sed?

When i said i am following GNU sed, what i meant was, that i followed the sed coding rules laid out by GNU. But not exactly...

Sorry if i am still driving you nuts. :)

Regards
James R. Ferguson
Acclaimed Contributor

Re: sed substitution using reg exp commands not working on HP-UX. Need help.

Hi :

> I made a small change to your code and it worked. :)
> Thanks a lot.
> I appreciate all your help.

If you are happy with the answers you received, please read:

http://forums13.itrc.hp.com/service/forums/helptips.do?#28

Since you are new to the Forums, "welcome!".

Regards!

...JRF...
sree sakamuri
Advisor

Re: sed substitution using reg exp commands not working on HP-UX. Need help.


Will do it for sure.

You deserve it.

Best Regards
Steven Schweda
Honored Contributor

Re: sed substitution using reg exp commands not working on HP-UX. Need help.

> [...] how to make sure that both Linux and
> HP-UX are using GNU sed?

On a GNU/Linux system, I'd expect "sed" to be
GNU "sed".

sed --version

On HP-UX, you'd need to install GNU "sed".
After it's installed, you can run whichever
"sed" you wish to run by specifying an
appropriate path. For example

/usr/bin/sed
/usr/local/bin/sed

If you say only "sed", then what you get
depends on your PATH. Depending on your
shell:

which sed
type sed

echo $PATH

man
sree sakamuri
Advisor

Re: sed substitution using reg exp commands not working on HP-UX. Need help.


Hello Steven

Many Thanks for your reply.

That will make my life easier going forward.
Will keep a note of this for future reference.

Best Regards
sree sakamuri
Advisor

Re: sed substitution using reg exp commands not working on HP-UX. Need help.


Please refer to the updates for solution.