删除以特定文本或单词结尾的行 - 在 Perl 脚本中

Delete line end with specific text or word - in Perl script

我想从文本文件中删除仅包含单词或字母“com-”的行,即以 com- 结尾的行将被删除 以下脚本仅删除 com- 你能帮忙吗?

open my $input, '<', 'inputfile.txt' or die "$!";
open my $out, '>',   'output.txt' or die $!;
while (<$input>){
    chomp;
    s/com-//g;
    print $out "$_\n";
}
close($input);
close($out);

我的inputfile.txt

10.22.10.12   com-sys28598001
10.21.19.2    com-
10.21.23.3    com-
3.8.3.13      com-
10.22.51.11   com-sys28019338
10.22.7.13    com-
10.22.64.3    com-sts28553063
10.24.18.21   com-sts29290004
10.24.14.24   com-sys24887111

渴望output.txt

10.22.10.12   com-sys28598001
10.22.51.11   com-sys28019338
10.22.64.3    com-sts28553063

只输出不以com-结尾的行。

while (<$input>){
    chomp;
    print $out "$_\n" unless /com-$/;
}

/com-$/ 仅匹配以 com-.

结尾的字符串

一个班轮

cat inputfile.txt | perl -e "while(<>) { print unless /com-$/}"

perl -ne "print unless /com-$/" < inputfile.txt