- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- using sed on hp-ux
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
Discussions
Discussions
Forums
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
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
тАО02-02-2010 04:07 AM
тАО02-02-2010 04:07 AM
test1
test2
test3
BEGIN
test4
test5
test6
END
test7
test8
test9
BEGIN
test10
test11
END
----
Now I want to have the file modified in such a way that what ever is there in between BEGIN and END should be deleted provided BEGIN statement should exist.
The output should be
---
test1
test2
test3
BEGIN
test7
test8
test9
BEGIN
using sed as
sed '/^BEGIN/,/^END/{//p;d;}' test.txt | sed '/^END/d'
I was able to perform well enough on other linux envirinments but not on hp-ux.
This statement is deleting BEGIN also.
Please help me on this
Thanks
Solved! Go to Solution.
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2010 05:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2010 05:23 AM
тАО02-02-2010 05:23 AM
Re: using sed on hp-ux
Many thanks for the solution. I got the answer as needed.
Lets say if we have ;[BEG_INCLUDE]%I .... ;[END_INCLUDE] instead of BEGIN...END respectively.
For example
test1
test2
test3
;BEG_INCLUDE]%I Begin
test4
test5
test6
;[END_INCLUDE]
test7
test8
test9
;[BEG_INCLUDE]%I Begin
test10
test11
;[END_INCLUDE]
When I tried with your perl statement it said
# perl -ne (/^\;\[BEG_INCLUDE\]\%I/../^\;\[END_INCLUDE\]/) {next unless /^\;\[BEG_INCLUDE\]\%I/};print' test_include.txt
ksh: syntax error: `(' unexpected
# perl -ne (/^;[BEG_INCLUDE]%I/../^;[END_INCLUDE]/) {next unless /^;[BEG_INCLUDE]%I/};print' test_include.txt
ksh: syntax error: `(' unexpected
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2010 05:37 AM
тАО02-02-2010 05:37 AM
Re: using sed on hp-ux
You used:
# perl -ne (/^;[BEG_INCLUDE]%I/../^;[END_INCLUDE]/) {next unless /^;[BEG_INCLUDE]%I/};print' test_include.txt
...but it needs to be:
# perl -ne 'if (/^;[BEG_INCLUDE]%I/../^;[END_INCLUDE]/) {next unless /^;[BEG_INCLUDE]%I/};print' test_include.txt
...that is, you dropped the leading single quote after the options '-ne' and you lost the 'if'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2010 05:39 AM
тАО02-02-2010 05:39 AM
Re: using sed on hp-ux
Just overlooked at the syntax.
Thanks a bunch!!
I got the solution.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2010 07:07 AM
тАО02-02-2010 07:07 AM
Re: using sed on hp-ux
> envirinments but not on hp-ux [...]
If you prefer the way that GNU "sed" works,
then it should be possible to install and use
GNU "sed" on your HP-UX system, too.
http://www.gnu.org/software/sed/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2010 11:33 PM
тАО02-02-2010 11:33 PM
Re: using sed on hp-ux
It appears that your immediate problem is that your "//" doesn't particularly match anything predictable. Though sed(1) says:
a /regular expression/ in the style of ed(1) modified thus:
And ed(1) says:
The null RE (for example, //) is equivalent to the last RE encountered.
This implies your command is:
sed '/^BEGIN/,/^END/{/^END/p;d;}' ...
So change it to:
sed '/^BEGIN/,/^END/{/^BEGIN/p;d;}' ...
Which matches what JRF had to use in perl.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-03-2010 02:21 AM
тАО02-03-2010 02:21 AM
Re: using sed on hp-ux
Thanks for the idea.
Yes it worked perfectly with the sed you have suggested.
Actually, I wrote a script that actually deletes the block of code in between
;[BEG_INCLUDE] %i filename.txt
...
...
...
;[END_INCLUDE]
and replaces the string
;[BEG_INCLUDE] %i filename.txt to
%i filename.txt
The script which I wrote as
sed '/^\;\[BEG_INCLUDE\]\%I/,/^\;\[END_INCLUDE\]/{//p;d;}' $pgm_name | sed '/^\;\[END_INCLUDE\]/d' > $Temp_Name
sed 's/;\[BEG_INCLUDE\]\%I/\%I/g' $Temp_Name > $Wrk_Name
These two statements performs the above said operation and was infact working on CentOS and all other Linux flavours but not at all on HP-UX korn shell.
But now I understood better on sed and many thanks for the solution.
Thanks