- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- grep in surrounding area
Operating System - HP-UX
1752402
Members
5650
Online
108788
Solutions
Forums
Categories
Company
Local Language
юдл
back
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
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
тАО05-03-2010 11:11 PM
тАО05-03-2010 11:11 PM
Hello Team,
I'm looking for a way of grepping a keyword in a file, but also to find the surrounding area.
Let me give you an example
******************myfile.txt***********
hostname=A
IP-ADDRESS=B
hostname=C
IP-ADDRESS=D
hostname=E
IP-ADDRESS=F
***************************************
So now I'm looking for a way to "grep" the file in such a way that I will be able to "find the IP-ADDRESS of hostname C"
so I could do
grep "hostname=C" myfile.txt + display the next line, but I have no idea in how to do that in an proper way.
Any ideas ?
brgds,
Raf
I'm looking for a way of grepping a keyword in a file, but also to find the surrounding area.
Let me give you an example
******************myfile.txt***********
hostname=A
IP-ADDRESS=B
hostname=C
IP-ADDRESS=D
hostname=E
IP-ADDRESS=F
***************************************
So now I'm looking for a way to "grep" the file in such a way that I will be able to "find the IP-ADDRESS of hostname C"
so I could do
grep "hostname=C" myfile.txt + display the next line, but I have no idea in how to do that in an proper way.
Any ideas ?
brgds,
Raf
Solved! Go to Solution.
- Tags:
- grep
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-03-2010 11:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-03-2010 11:30 PM
тАО05-03-2010 11:30 PM
Re: grep in surrounding area
Hello,
the awk example seems to work ! Thx.
Just waiting for maybe new clues, but this is already the best thing I've tested !
Raf
the awk example seems to work ! Thx.
Just waiting for maybe new clues, but this is already the best thing I've tested !
Raf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-05-2010 06:49 AM
тАО05-05-2010 06:49 AM
Re: grep in surrounding area
Hi Raf:
Thie Perl solution will give both the line before and after the matching one:
# perl -ne 'BEGIN{$token=shift};if (m{$token}) {print $prev,$_;$_=<> and print unless eof};$prev=$_' hostname=C myfile.txt
Regards!
...JRF...
Thie Perl solution will give both the line before and after the matching one:
# perl -ne 'BEGIN{$token=shift};if (m{$token}) {print $prev,$_;$_=<> and print unless eof};$prev=$_' hostname=C myfile.txt
Regards!
...JRF...
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP