- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Scripting challenge
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
03-25-2004 10:28 PM
03-25-2004 10:28 PM
gb656_1
/usr4/SDF
/usr4/LXD
/usr4/DFG
gb650_1
/usr4/FGH
/usr4/OIU
What I want to do is grep for a specific /usr4/??? line in the file. This is fine but is there anyway that same grep command could display the line plus a certain number of lines above/below the line I am grepping for? Basically as well as telling me the line exists I would also like to display the server (gb656_1) it is associated with.
Any ideas?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2004 10:33 PM
03-25-2004 10:33 PM
Re: Scripting challenge
grep -B 3 LXD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2004 10:33 PM
03-25-2004 10:33 PM
Re: Scripting challenge
You can also use the extended features of GNU grep, which is MUCH better than the grep you get from HP
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2004 10:55 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2004 10:56 PM
03-25-2004 10:56 PM
Re: Scripting challenge
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2004 10:59 PM
03-25-2004 10:59 PM
Re: Scripting challenge
Singapore https://www.beepz.com/personal/merijn/
Rotterdam http://www.cmve.net/~merijn/
Seattle http://ww.hpux.ws/merijn/
or from http://hpux.connect.org.uk/hppd/hpux/Gnu/grep-2.5.1/
in order to have it overrule HP's grep, just e sure to have your $PATH changed so that it finds GNU grep before HP's grep
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2004 10:59 PM
03-25-2004 10:59 PM
Re: Scripting challenge
http://hpux.connect.org.uk/hppd/hpux/Gnu/grep-2.5.1/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2004 11:17 PM
03-25-2004 11:17 PM
Re: Scripting challenge
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2004 11:38 PM
03-25-2004 11:38 PM
Re: Scripting challenge
The tricky bit is the lines before the pattern, which have to be kept in a buffer.
To show 10 lines before, 8 after, use something like:
awk -v before=10 -v after=8 '
{ibuf[NR]=$0}
/\/user4\/xxx/ {for (i=NR-before;i
counter=after+1}
(counter>0) {counter--;print}
' YOURFILE
This isn't terribly efficient as it saves every line in a buffer, although it does clear the buffer out each time it encounters the search string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2004 01:56 AM
03-26-2004 01:56 AM
Re: Scripting challenge
Matthew,
Sounds like all you had to do is teach awk (or perl) to remember the lastserver node seen and report that upon match:
awk '/^[^\/]/{node=$0} /FGH/{print node " : " $0}' x
gb650_1 : /usr4/FGH
Graham wrote:
" The tricky bit is the lines before the pattern, which have to be kept in a buffer."
:
" This isn't terribly efficient as it saves every line in a buffer"
Using the modulus operator "%" it is trivial to create a small 'circular' buffer. See below.
", although it does clear the buffer out each time it encounters the search string."
That might not be desritable in case you can have two matches within the selected window size.
Here is a one-line 'circular buffer" example with windows size in variable W (4):
awk 'BEGIN {W=4} {line[i++%W]=$0} /FGH/{for (j=i-W;j
hth someone,
Hein.