in reply to Re^6: Search and delete
in thread Search and delete

It seems that you are not really deleting lines from a file, more filtering the output of a command.

Would it be safe to assume that you would want to resume printing when the next line starts with 'array'? If so, I would suggest setting a print flag to 1 initially, and then in the loop setting it to 0 if 'unassigned' shows up, and reset it to 1 if 'array' shows up. Then print to output if the print flag = 1.

my %unitMap; my $cmd = "hpacucli ctrl slot=0 pd all show";; open my $fd, "$cmd|" or return \%unitMap; my $printit = 1; while (my $row = <$fd>) { next if $row =~ /^$|Smart/; $printit = 0 if $row =~ /^\s*unassigned$/; $printit = 1 if $row =~ /^\s*array .$/; next unless $printit; # moved processing to here; no need to manipulate lines you're + not going to print anyway $row =~ s/^\s+//; $row =~ s/[,|)|(]//g; print "$row"; } close $fd;
1 Peter 4:10