0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

awkコマンドでファイル比較:差異がある行数、項目番号、値をファイル出力

Posted at

./awkDiffFile.sh A.txt B.txt

awkDiffFile.sh

#!/bin/bash

awk -v f1="$1" -v f2="$2" '
BEGIN {
FS = OFS = ",";
print "rowNum,columnNum," f1 "," f2;
}

FNR==NR {
    for(i=1; i<=NF; i++) data[FNR,i]=$i;
    max_col = (NF > max_col) ? NF : max_col;
    next;
}

{
    for(i=1; i<=NF || i<=max_col; i++) {
        if ($i != data[FNR,i]) {
            print FNR, i, data[FNR,i], $i;
        }
    }
}

' $1 $2 > diff_report.csv

cat diff_report.csv

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?