- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Print lines after search pattern
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
01-30-2009 05:41 AM
01-30-2009 05:41 AM
I am searching for a pattern in all the log files
I want to know how to print n lines following the first occurrence of the search pattern in the file.
Regards,
Gyan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2009 05:50 AM
01-30-2009 05:50 AM
Re: Print lines after search pattern
# perl -ne '/pattern/ and $n=3;print if ($n-- >0)' file
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2009 06:35 AM
01-30-2009 06:35 AM
SolutionWith match line:
awk '/pattern/ { x=5 } x-- > 5'
Without match line:
awk 'x-- > 0; /pattern/ { x=5 }'
That 'x-- > 0' test wether x is greater than 0 and subtracts on from x. If it was true then... nothing: the default action it taken which is to print the current input line.
The part '/pattern/ { x=5 }' looks for a match againt whatever pattern text you provide, and if true sets x to a value, here 5 in the example.
Hein.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2009 02:56 PM
01-30-2009 02:56 PM
Re: Print lines after search pattern
-A, --after-context=NUM print NUM lines of trailing context
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2009 10:58 PM
02-01-2009 10:58 PM
Re: Print lines after search pattern
Thanks everybody.