当前位置: 代码迷 >> 综合 >> perl把不匹配的那些行打印出来
  详细解决方案

perl把不匹配的那些行打印出来

热度:76   发布时间:2024-01-20 11:26:31.0

1.经常会遇到把不匹配某些特征的行打印出来。可以用!~来操作(含义是不匹配)。

#! /usr/bin/perl

use 5.010;
use strict;

if (-e "get_file.txt"){
    say "get_file is exist";
    unlink "get_file.txt";
    say "get_file is delete";
    }

open my $fix_file,'>',"get_file.txt" ;

while(<>){
    if (/w_mps|rake_post|lte_csi|lte_cst|u_pss_top/){
        if ($_ !~ /pmi/){
        #if ($_ !~ /pmi.*data/){
        printf $fix_file $_;
        }
        }
    }
close $fix_file;