区分两个文件之间的文本块的最佳方法是什么?
What's the best way to diff blocks of text between two files?
我可以使用什么 diff 标志或其他工具来比较两个文件的文本块差异。例如:
文件 1
record {
data1
data2
}
文件 2
record {
data1
data2
}
record {
data3
data4
}
输出会像
record {
data3
data4
}
您可以使用 diff
命令作为
diff -a --suppress-common-lines file2 file1
(或)将grep
用作
grep -Fxvf file1 file2
带有以下标志,
-F, --fixed-strings
Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched.
-x, --line-regexp
Select only those matches that exactly match the whole line.
-v, --invert-match
Invert the sense of matching, to select non-matching lines.
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. The empty file contains zero patterns, and therefore matches nothing.
使用awk
的另一种方式
awk 'NR == FNR {unique[[=13=]]++; next} !([=13=] in unique)' file1 file2
我可以使用什么 diff 标志或其他工具来比较两个文件的文本块差异。例如:
文件 1
record {
data1
data2
}
文件 2
record {
data1
data2
}
record {
data3
data4
}
输出会像
record {
data3
data4
}
您可以使用 diff
命令作为
diff -a --suppress-common-lines file2 file1
(或)将grep
用作
grep -Fxvf file1 file2
带有以下标志,
-F, --fixed-strings
Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched.
-x, --line-regexp
Select only those matches that exactly match the whole line.
-v, --invert-match
Invert the sense of matching, to select non-matching lines.
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. The empty file contains zero patterns, and therefore matches nothing.
使用awk
awk 'NR == FNR {unique[[=13=]]++; next} !([=13=] in unique)' file1 file2