- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: sed substitution using reg exp commands not wo...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2010 02:47 AM
04-15-2010 02:47 AM
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) main code to strip off the abs paths of the cmds. **IMP**IMP**
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
Solved! Go to Solution.
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2010 05:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2010 05:32 AM
04-15-2010 05:32 AM
Re: sed substitution using reg exp commands not working on HP-UX. Need help.
Thanks for your reply.
Tried your suggestion but no luck.
Still the same error...
i used as below,
sed -e "1i\
$top" $DEST_DIR/$1 > $DEST_DIR/new_$1
Please correct me.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2010 05:44 AM
04-15-2010 05:44 AM
Re: sed substitution using reg exp commands not working on HP-UX. Need help.
Sorry, try this:
top=mystartpoint
echo "/path/to/file" | sed -e '1i\
'$top
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2010 05:52 AM
04-15-2010 05:52 AM
Re: sed substitution using reg exp commands not working on HP-UX. Need help.
Thanks for your quick reply.
Unfortunately this too doesn't work
the code i tried was,
echo $DEST_DIR/$1 | sed -e "1i\
"$top > $DEST_DIR/new_$1
sed: Function 1i#!/usr/bin/ksh cannot be parsed.
Please correct me if i am wrong.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2010 06:21 AM
04-15-2010 06:21 AM
Re: sed substitution using reg exp commands not working on HP-UX. Need help.
Change the double quotes to single quotes as I wrote in my second post:
echo $DEST_DIR/$1 | sed -e '1i\
'$top > $DEST_DIR/new_$1
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2010 06:21 AM
04-15-2010 06:21 AM
Re: sed substitution using reg exp commands not working on HP-UX. Need help.
> fine on Linux, aren't working on HP-UX.
Have you tried using GNU "sed" on the HP-UX
system?
http://www.gnu.org/software/sed/
ftp://ftp.gnu.org/gnu/sed/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2010 06:33 AM
04-15-2010 06:33 AM
Re: sed substitution using reg exp commands not working on HP-UX. Need help.
I changed to single quotes and used it on 3) of my original query. But now i am getting a different error.
code i used,
echo $DEST_DIR/$1 | sed -e '2i\
'export PATH=\$PATH:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin/ > $DEST_DIR/new_$1
sed: Cannot find or open file PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin/.
Sorry for the change as for 2) is solved using another workaround.
Yes, I followed GNU sed.
THanks & Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2010 06:38 AM
04-15-2010 06:38 AM
Re: sed substitution using reg exp commands not working on HP-UX. Need help.
> Sorry for the change as for 2) is solved using another workaround.
Do you mean that my suggestion didn't work for you and that you did something different? To see what you "workaround" was would be nice.
> Yes, I followed GNU sed.
What does that mean; that you installed or *used* GNU 'sed' in lieu of the HP-UX 'sed'?
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2010 06:42 AM
04-15-2010 06:42 AM
Re: sed substitution using reg exp commands not working on HP-UX. Need help.
Try:
echo $DEST_DIR/$1 | sed -e '2i\
'"export PATH=\$PATH:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin/" > $DEST_DIR/new_$1
That is, double-quote the "export PATH= ..."
so that 'sed' doesn't think that this is a file which it is to open an process.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2010 06:45 AM
04-15-2010 06:45 AM
Re: sed substitution using reg exp commands not working on HP-UX. Need help.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2010 06:57 AM
04-15-2010 06:57 AM
Re: sed substitution using reg exp commands not working on HP-UX. Need help.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2010 07:07 AM
04-15-2010 07:07 AM
Re: sed substitution using reg exp commands not working on HP-UX. Need help.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2010 07:07 AM
04-15-2010 07:07 AM
Re: sed substitution using reg exp commands not working on HP-UX. Need help.
>
> 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2010 07:13 AM
04-15-2010 07:13 AM
Re: sed substitution using reg exp commands not working on HP-UX. Need help.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2010 07:13 AM
04-15-2010 07:13 AM
Re: sed substitution using reg exp commands not working on HP-UX. Need help.
> 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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2010 07:18 AM
04-15-2010 07:18 AM
Re: sed substitution using reg exp commands not working on HP-UX. Need help.
Will do it for sure.
You deserve it.
Best Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2010 10:32 AM
04-15-2010 10:32 AM
Re: sed substitution using reg exp commands not working on HP-UX. Need help.
> 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2010 12:16 AM
04-16-2010 12:16 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2010 12:33 AM
04-16-2010 12:33 AM
Re: sed substitution using reg exp commands not working on HP-UX. Need help.
Please refer to the updates for solution.