Hi, I need guidance with this perl script . I am trying to print a block of lines (say 5 lines at a time). I do have a start line and an end line. I have to look into multiple flat files from which I will be accessing that block. my block of code that I have written is as follows:
open(MYINPUTFIL3, <DATA>); MYINPUTFIL3: my $spool1 = 0; my @a; while (<MYINPUTFIL3>) { if (/start line:/i) { $spool1 = 1; next; } elsif (/End Line:/i) { print map { "$_" } @a; $SYS=$_; $SYS =~ s/\r|\n//g; $SYS=~ s/^\s+//; $SYS=~ s/\s+$//; $SYS1 = $SYS; $SYS2 = $SYS; $SYS2 = s/[^a-zA-Z]*//g; $SYS1 =~ s/[^0-9.]*//g; @a = (); } if ($spool1) { push (@a, $SYS); $SYS=$_; $SYS =~ s/\r|\n//g; $SYS=~ s/^\s+//; $SYS=~ s/\s+$//; $SYS1 = $SYS; SYS2 = $SYS; $SYS2 = s/[^a-zA-Z]*//g; $SYS1 =~ s/[^0-9.]*//g; last; } } close DATA;
Let me give example of input and output data here:
Input Data:
id1 : /a text lies here/
add name: new add1
ph no: new phone1
country: new country1
id2 : /some other text lies here/
add name: new add2
ph no: new phone2
country: new country2
Desired output:
id2:/some other text lies here/ add name: new add2 ph no: new phone2 country: new country2
So my question is as follows.
1. it prints the details for the Id1 and not Id2 even though I am giving id2 in the if statement (for start Line)
2. I want next 4 lines to be printed. But it prints only one line after the start line.
3. I get output which is distorted(with tabs and new line in it)
Please guide...Stuck....
In reply to printing alternate lines from a file by perl_req
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |