extracting lines
Anonymous Monk
created: 2004-07-02 06:31:08
Hi all, I need to remove entries in a txt file. The entries to remove, must start with a pattern /phn/ then end on /1ord/. e.g
# input phn
..
..
# 1ord
Used the following:
if (/phn_a/ ... /1ord/) {
     print OUT $_;      }
But this prints out the first finding of phna_ through to first 1ord. 5 lines separate these patterns in the text file Tried this also, but this seems to starts printing from a poisiton i dont expect it to:
$nLines = 5 if ( /1ord$/  );
     print OUT if $nLines-- > 0;
Re: extracting lines
created: 2004-07-02 06:38:30
Try unless instead of if.
print OUT unless (/phn_a/ .. /1ord/);
UPDATE: more detailed:
#!/usr/bin/perl

use strict;
use warnings;

while () {
  print unless (/phn/ .. /1ord/);
}

__DATA__
black
# input phn
blue
red
green
# 1ord
yellow
white
Re^2: extracting lines
created: 2004-07-02 06:43:40
this appears to print everything in the file, no change
Re^3: extracting lines
created: 2004-07-02 06:46:41
sorry just seen the update
Re^4: extracting lines
created: 2004-07-02 06:51:17
only problem here, is that it omits everything e.g
# phn
..
..
# xxxxx
# phn
..
..
# 1ord
so here the code would onit both rather than just the second?
Re^5: extracting lines
created: 2004-07-02 07:02:01
Yes, it starts with the first "phn" and it ends with the first "lord". Everything between get lost. It can't work properly if the file isn't structured this way.

perlmonks.org content © perlmonks.org and Anonymous Monk, neniro

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03