Perl reading file, printing unique value from a column

后端 未结 3 1764
遥遥无期
遥遥无期 2021-01-24 13:09

I am new to perl, and i\'d like to achieve the following with perl.

I have a file which contain the following data:

/dev/hda1 /boot ext3 rw          


        
3条回答
  •  鱼传尺愫
    2021-01-24 13:40

    #!/usr/bin/perl
    
    my %hash ;
    while (<>) {
    if (/\s*[^\s]+\s+[^\s]+\s+([^\s]+)\s+.*/) {
        $hash{$1}=1;
    }
    }
    print join("\n",keys(%hash))."\n";
    

    Usage:

     ./.pl file1 fil2 ....
    

提交回复
热议问题