0

我有这个脚本,它用于比较两个文件中的第一个字段,我希望它忽略大小写,尝试添加一行 IGNORECASE = 1; 但似乎不起作用,

你能告诉我如何忽略案例吗?

BEGIN {
   FS=OFS=";"
}

FNR==NR {
   array[$1]=$2
   next
}

{
   if ($1 in array) { 
      print $1";" array[$1]";" $2
   }

   else {
      if ($2 in values) {
         print  $1";" "only_at_" FILENAME ";" $0 " same path    as " values[$2]
      }
      else {
         print  $1";" "only_at_" FILENAME ";" $0 " no path  found"
      }
   }
   values[$2]=$1
}

假设我有

文件 1

\\FILE48\bucan-CFAN_Subcommittees;\\SERVER24\dfs\Shared\can\CFAN Subcommittees

文件2

\\file48\bucan-CFAN_Subcommittees;/fs8_100g/FILE48/BU/can/CFAN Subcommittees
\\FILE58\userhome_e;/fs1_100g/FILE58/userhome

预期产出

\\FILE48\bucan-CFAN_Subcommittees;\\SERVER24\dfs\Shared\can\CFAN Subcommittees;/fs8_100g/FILE48/BU/can/CFAN Subcommittees
\\MLISFILE58\userhome_e;only_at_file2;\\MLISFILE58\userhome_e;/fs1_100g/MLISFILE58/userhome no path found
4

1 回答 1

1

Pretty simple with the join command

join -t';' -i -j 1 -o 1.1,1.2,2.2 File1 File2

Using ";" as a field separator, case-insensitively join the two files on field 1, and output the first and second fields from file1 and the 2nd field from file2.

If you really want awk, this will do the same thing:

awk '
   BEGIN {FS=OFS=";"} 
   NR==FNR {key[tolower($1)] = $0; next} 
   tolower($1) in key {print key[tolower($1)], $2}
 ' file1 file2
于 2012-09-15T21:45:14.910 回答