- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- PERL pattern matching
Operating System - Linux
1820266
Members
2921
Online
109622
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
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
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
тАО12-29-2006 01:31 PM
тАО12-29-2006 01:31 PM
PERL pattern matching
I am writing a PERL script which is required to search a pattern and display 2 lines before the first occurance of the pattern.
Somehow I am not able to get the information using my script.
Can anyone please let me know how to do it.
Thanks,
Anand
Somehow I am not able to get the information using my script.
Can anyone please let me know how to do it.
Thanks,
Anand
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-29-2006 02:01 PM
тАО12-29-2006 02:01 PM
Re: PERL pattern matching
Please try to GOOGLE your questions before posting.
This has been asked and answered many many times before. For example in this forum:
Google: +perl +lines +before +site:itrc.hp.com
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=630972
Hein.
This has been asked and answered many many times before. For example in this forum:
Google: +perl +lines +before +site:itrc.hp.com
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=630972
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-29-2006 02:42 PM
тАО12-29-2006 02:42 PM
Re: PERL pattern matching
Hi:
Here's a simple solution:
# cat .findpat
#!/usr/bin/perl
use strict;
use warnings;
my $pat = shift;
my @lines;
while (<>) {
shift @lines if $#lines >= 2;
if (/$pat/) {
print for @lines;
print;
}
push( @lines, $_ );
}
1;
...Run as:
# ./findpat pattern file
Regards!
...JRF...
Here's a simple solution:
# cat .findpat
#!/usr/bin/perl
use strict;
use warnings;
my $pat = shift;
my @lines;
while (<>) {
shift @lines if $#lines >= 2;
if (/$pat/) {
print for @lines;
print;
}
push( @lines, $_ );
}
1;
...Run as:
# ./findpat pattern file
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.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP