Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

hp ux version of sed command

SOLVED
Go to solution
Hemang75
Occasional Visitor

hp ux version of sed command

wanted a similar sed command for hp ux
sed '/Pattern/,+4 d' - works fine in Linux.
7 REPLIES
Steven E. Protter
Exalted Contributor

Re: hp ux version of sed command

Shalom,

Did you try it in HP-UX?

Does it actually work differently than in Linux?

sed is kind of sed. I can't remember it acting differently in HP-UX and Linux. I'm not a heavy user but have exchanged sed scripts between the two without a second thought.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Hemang75
Occasional Visitor

Re: hp ux version of sed command

yes, I tried using with Linux and it works but not with HP-UX
Bob E Campbell
Honored Contributor

Re: hp ux version of sed command

Fun with regular expressions.

I thought that it worked on HP-UX, but that it was supposed to be dot relative (.+4). Could not get it to work...

Scratching my head I hopped into vi and used the colon escape ":g/Pattern/,.+4 d" and it worked just fine. Everybody is gone for the holiday, perhaps an answer will show up next week.
James R. Ferguson
Acclaimed Contributor
Solution

Re: hp ux version of sed command

Hi:

Well the GNU versions of many utilities are far more feature-rich than the HP-UX ones, so this doesn't surprise me in the least.

In fact, the GNU documentaion notes that the form:

addr1,+N

...is a GNU extension that matches addr1 and the N lines following addr1.

We can emulate your 'sed' command by using a bit of Perl which in this case is easy enough to deduce:

# perl -ne 'm/Pattern/ and $i=1,next;next if $i && $j++<4;print' file

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: hp ux version of sed command

Hi (again):

If you like, you can fetch a GNU 'sed' from the Porting Centre. Be sure to get the run-time dependencies for a binary; or the build-time dependencies if you are compiling your own.

http://hpux.connect.org.uk/hppd/hpux/Gnu/sed-4.2.1/

Lastly, as a new member to the ITRC, welcome! When you are satisfied with the answers you have received, please read:

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

Regards!

...JRF...
Hemang75
Occasional Visitor

Re: hp ux version of sed command

Thanks Bob and James.. Appreciate your reply..
James R. Ferguson
Acclaimed Contributor

Re: hp ux version of sed command

Hi:

Assigning points is a way of saying "thank you" and marking the thread to indicate to future readers which answers helped you to resolve your problem. Points increase the value of our community.

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

Regards!

...JRF...