- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Perl script to print lines in file...
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
Discussions
Discussions
Discussions
Forums
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
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
тАО10-05-2005 02:11 AM
тАО10-05-2005 02:11 AM
-Hazem
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-05-2005 02:23 AM
тАО10-05-2005 02:23 AM
Re: Perl script to print lines in file...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-05-2005 02:31 AM
тАО10-05-2005 02:31 AM
Re: Perl script to print lines in file...
while(
$found=$. if /expression/;
if ($found) {
print @a if @a;
undef @a;
print $_ if $found+5 > $.;}
} else {
push(@a,$_);
shift(@a) if @a > 5;
}
}
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-05-2005 02:50 AM
тАО10-05-2005 02:50 AM
Re: Perl script to print lines in file...
For example:
==============
line1
line2
line3
line4
line5
line6
line7
line8
line9
line10
===============
Clay, it is an ascii file, but it has a few weird binary characters in it and there are also no new lines in it either. Thanks you guys!
-Hazem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-05-2005 03:06 AM
тАО10-05-2005 03:06 AM
Re: Perl script to print lines in file...
You could change the definition of the problem to something like N characters (more accurately N bytes) before some pattern and N characters after some pattern.
At this point, you are simply not describing the problem well enough. Of course, in many cases when the problem is ddescribed well, the solution is then very simple --- and often obvious.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-05-2005 03:08 AM
тАО10-05-2005 03:08 AM
Re: Perl script to print lines in file...
open INP,'your_file';
print "\n==============\n";
while(
$found=$. if /pattern/;
if ($found) {
print @a if @a;
undef @a;
print $_ if $found+6 > $.;
}
else {
push(@a,$_);
shift(@a) if @a > 5;
}
}
print "==============\n\n";
close INP;
Regards,
Sergejs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-05-2005 03:14 AM
тАО10-05-2005 03:14 AM
Re: Perl script to print lines in file...
Clay, ok, let's assume it is an ascii file. The problem is that when we tried using awk, it was not able to interpret the file. So, all we know is that perl can match the pattern we want, and awk cannot. I apologize for not explaining it correctly. So assuming it is an ascii file, how can we do that in perl. Thanks!
-Hazem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-05-2005 04:47 AM
тАО10-05-2005 04:47 AM
Solution$rng=5;
while(
$found=$. if /expresson/;
if (! $found) {
push(@a,$_);
shift(@a) if $a > $rng;
} elsif ($found+$rng > $.) {
print "=========\n";
$found=0;
} else {
if (scalar @a) {
print "=========\n";
print @a;
undef @a;
}
print $_;
}
}
Rod Hills