|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
got one way
Quote:
Code:
my @buffer;
$#buffer = 1;
open(IN, $file)|| die("Could not open file");
while(<IN>){
push@buffer => $_;
shift@buffer;
}
close(IN);
open(IN, $file)|| die("Could not open file");
while(<IN>){
print $buffer[0] if/^\*Main Start/ ;
}
close(IN);Regards, prady |
| Sponsored Links | ||
|
|
|
|||
|
Quote:
But when I am trying to use the module Tie::File I am getting the follwing error. Code:
Can't locate Tie/File.pm in @INC (@INC contains: /usr/perl5/5.00503/sun4-solaris /usr/perl5/5.00503 /usr/perl5/site_perl/5.005/sun4-solaris /usr/perl5/site_perl/5.005 .) at ./mdl.pl line 5. BEGIN failed--compilation aborted at ./mdl.pl line 5. This is first time I'll use a module so pls if I am doing something wrong with my code pls suggest me. Code:
use Tie::File;
tie @array, 'Tie::File', $file or die ("Could not open file");
print $array[13] ;Regards, user_prady Last edited by user_prady; 03-31-2008 at 04:14 AM.. |
|
|||
|
Tie::File has been a core module for a while, but I am not sure since when. The problem is that your server is using a very old version of perl 5.005, so either it was not included with the distribution of perl you have or it was removed for some reason.
|
|
|||
|
You could do something like this: Code:
use strict;
use warnings;
my $flag = 0;
my $last_line;
while(<DATA>){
if(/^\*Main Start/){
$flag = 1;
}
elsif($flag && /^\*Main End/) {
$numbers = (split(',',$last_line))[0];
$last_line = '';
$flag = 0;
print $numbers,"\n";
}
else {
$last_line = $_;
next;
}
}
__DATA__
*Init End
*Main Start
*Comment Reset Timers
000000,0000,0,0,0,0,0,1,0
000000,0000,0,0,0,0,1,1,0
*Comment Control Frame at 1.04596 ms
000000,0400,0,0,0,0,1,0,1
2418A4,0000,0,1,3,0,0,0,0
049C00,0000,0,0,2,0,0,0,0
*Comment Control Frame at 1.04673 ms
*Comment Control Frame at
000002,0000,0,0,0,0,1,0,1
241002,0000,0,1,3,0,0,0,0
000100,0000,0,0,2,0,0,0,0
*Comment Control Frame at
000004,0000,0,0,0,0,1,0,1
241002,0000,0,1,3,0,0,0,0
000000,0000,0,0,2,0,0,0,0
*Comment Frame 13 at ** us,,,,,,,,
000005,7E3D,0,0,0,0,1,0,1
*Main End,,,,,,,, |
|
|||
|
Quote:
I read your previous article how to fix the problem on the module issue Perl - read a line from a file and writing to the same line in the file But still getting the error.... Anyway many many thanks for your time and given code. I'll try it. Regards, prady |
|
|||
|
Quote:
Regards, user_prady |
|
|||
|
With the sample data you posted, the code I posted does that, it prints 000005.
|
| Sponsored Links |
|
|
![]() |
| Bookmarks |
| Tags |
| perl, perl regex, perl shift, regex, shift, shift perl, solaris |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sed: find match and delete the line above | cstovall | Shell Programming and Scripting | 3 | 07-02-2008 11:31 PM |
| Perl: Match a line with multiple search patterns | Juha | Shell Programming and Scripting | 10 | 04-09-2008 02:43 AM |
| Multiple line match using sed | SiftinDotCom | Shell Programming and Scripting | 15 | 03-28-2008 02:12 PM |
| read and match multiple lines in perl | zx1106 | Shell Programming and Scripting | 5 | 03-14-2008 10:21 PM |
| sed - Replace Line which contains the Pattern match with a new line | kousikan | Shell Programming and Scripting | 2 | 03-24-2007 07:24 AM |