#!/usr/bin/perl
# You may need to change this path to /usr/local/bin/perl
$linecount = 0;
open (FILE,"input.txt");
@lines = <FILE>;
close (FILE);
open (FILE,">input.txt");
foreach $l (@lines) {
$linecount++;
if ($linecount ne 6 && $linecount ne 7 && $linecount ne 8 && $linecount ne 9) {
print FILE $l;
}
}
close (FILE);
exit;
If you mean the lines numbered 6 to 9, try:
#!/usr/bin/perl
# You may need to change this path to /usr/local/bin/perl
open (FILE,"input.txt");
@lines = <FILE>;
close (FILE);
open (FILE,">input.txt");
foreach $l (@lines) {
if ($l !~ /^6/ && $l !~ /^7/ && $l !~ /^8/ && $l !~ /^9/) {
print FILE $l;
}
}
close (FILE);
exit;
It's not working for the original poster because the lines do not start with the numbers.
Here is what he's actually starting with.
backups01laxint.liuc(s){jsandova}[~]<0>$ nsrjb -v | awk -F' ' '$3>=01{print $0}' | cut -b 1-79 | cat -n | grep -v "^[6-9] "
setting verbosity level to `1'
1 slot volume used pool barcode
2 1: intwindows.0005 9% intwindows 010159L2
3 2: intunix.0009 19% intunix 010155L2
4 4: intrman.0002 2% intrman 010395L2
5 24: Cleaning Tape (50 uses left) 000002L1 000002L1
6 *not registered in the NetWorker media data base
7 7 registered volume(s), 7 volumes are less than 80% full.
8 1335 GB estimated capacity, 1278 GB remaining (4% full)
9 Default slot range(s) are 1-23
Even my 2nd Perl version won't work. Need this:
#!/usr/bin/perl
# You may need to change this path to /usr/local/bin/perl
open (FILE,"input.txt");
@lines = <FILE>;
close (FILE);
open (FILE,">input.txt");
foreach $l (@lines) {
if ($l !~ /^(\s|\t)*[6-9]/) {
print FILE $l;
}
}
close (FILE);
exit;
Thanks for the input PWSwebmaster however that grep-v you adjusted still didn't work. The closest I can get is doing the following but it's still doesn't delete all the lines I want.
backups01laxint.liuc(s){jsandova}[~]<0>$ nsrjb -v | awk -F' ' '$3>=01{print $0}' | cut -b 1-79 | grep -v "("
setting verbosity level to `1'
slot volume used pool barcode
1: intwindows.0005 9% intwindows 010159L2
2: intunix.0009 19% intunix 010155L2
4: intrman.0002 2% intrman 010395L2
*not registered in the NetWorker media data base
danmero,
That is exactly what I was look for. Simple and short, I however have not used sed much so was not sure on how to implement it. Thanks for the great tip!