- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Context in HPUX grep
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
02-27-2008 06:11 AM
02-27-2008 06:11 AM
Hi,
is there any command in HPUX that can work like GNU grep that shows context lines (a few lines preceeding and succeeding the selected line)? It looks like HPUX grep can't do that. Thank you in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2008 06:22 AM
02-27-2008 06:22 AM
Solution# print 1 line of context before and after regexp, with line number
# indicating where the regexp occurred (similar to "grep -A1 -B1")
sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h
Taken from Handy One-Liners for SED (attached).
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2008 06:45 AM
02-27-2008 06:45 AM
Re: Context in HPUX grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2008 06:51 AM
02-27-2008 06:51 AM
Re: Context in HPUX grep
For that matter, you could fetch and install GNU's 'grep' from the HP-UX Porting Center:
http://hpux.asknet.de/hppd/hpux/Gnu/grep-2.5.3/
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2008 06:54 AM
02-27-2008 06:54 AM
Re: Context in HPUX grep
sed is OK. I would appreciate the final sed command that prints only preceding line and doesn't print line numbers. How can I get it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2008 07:07 AM
02-27-2008 07:07 AM
Re: Context in HPUX grep
sed -n -e '/regexp/{x;1!p;g;p;}' -e h filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2008 10:44 AM
02-27-2008 10:44 AM
Re: Context in HPUX grep
and is it possible to join these two lines together? I would like to have a preceding and matching line printed in one line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2008 10:59 AM
02-27-2008 10:59 AM
Re: Context in HPUX grep
> and is it possible to join these two lines together? I would like to have a preceding and matching line printed in one line.
# sed -n -e '/b/{x;1!p;g;p;}' -e h filename|paste -- - -
That's a double dash; whitespace; a single dash; whitespace; and another single dash.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2008 11:41 PM
02-27-2008 11:41 PM
Re: Context in HPUX grep
Modifying JRF's solution you can go sed crazy and do:
sed -n -e '/regexp/{H;g;s/\n/ /;p;}' -e h filename
(Note: It doesn't work too well if the pattern is on two sequential lines.)