- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: grep for word in text files but show neighbour...
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
09-21-2003 11:21 PM
09-21-2003 11:21 PM
grep for word in text files but show neighbouring lines
Thanks,
Matt.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2003 11:28 PM
09-21-2003 11:28 PM
Re: grep for word in text files but show neighbouring lines
I'm attaching the "handy one-liners for sed". I believe you'll find your solution there (if you don't mind using sed, that is).
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2003 02:42 AM
09-22-2003 02:42 AM
Re: grep for word in text files but show neighbouring lines
see http://hpux.cs.utah.edu/ to get a copy.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2003 01:54 PM
09-22-2003 01:54 PM
Re: grep for word in text files but show neighbouring lines
-A or --after-context
-B or --before-context
-C or --context
Each is followed by the number of lines you want before/after.
If you don't want to use GNU's grep though, you will have to use something like the sed solution posted above.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2003 05:04 PM
09-22-2003 05:04 PM
Re: grep for word in text files but show neighbouring lines
I'm afraid an sed or perl script will be the
way unless gnu-grep can be obtained.
Now if this question wat for one of HP's other fine operating systems then the anwer is easier.
Under OpenVMS it would be SEARCH/WINDO=(before,after).
Under Tru64: grep -p [for paragraph]
-pparagraph_separator
[Tru64 UNIX] Displays the entire paragraph containing matched lines.
Paragraphs are delimited by paragraph separators, paragraph_separator,
which are patterns in the same form as the search pattern. Lines con-
taining the paragraph separators are used only as separators; they are
never included in the output. The default paragraph separator is a
blank line.
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2003 04:24 AM
09-23-2003 04:24 AM
Re: grep for word in text files but show neighbouring lines
I fiddled with an awk command and put into the attached script. You can try running it like this:
#
which tries to find all occurrances of the string "murphy" plus the two lines proceeding and following "murphy" in the syslog.
regards,
John K.