小编Mar*_*n K的帖子

Perl regex one line file

I'm using cat to get content of the file, and then I use regex to get what I want. When I change order of if's in example i put PASSWORD as a second one, IP will be empty.

#!/usr/bin/perl
my $param = $ARGV[0];

my $IP;
my $PASSWORD;
my $MODEM;
my @cat = `cat file`;

 foreach my $line (@cat){
    if ($line =~ /$param/){
        if ($line =~ /MODEM:(\w+)/g){ $MODEM = $1; }
        if ($line =~ /IP:((\d{1,3}\.){3}\d{1,3})/g){ $IP = $1; }
        if ($line …
Run Code Online (Sandbox Code Playgroud)

regex perl file

2
推荐指数
2
解决办法
77
查看次数

标签 统计

file ×1

perl ×1

regex ×1