例如,我有两个文本文件:
file1.txt
line 1 file 1
line 2 file 1
...
file2.txt
line 1 file 2
line 2 file 2
...
我确定file1.txt
和file2.txt
的行数相同。
我想要的是如何使用以下格式导出到file3.txt
:
line 1 file 1
line 1 file 2
line 2 file 1
line 2 file 2
...
我只想逐行查看这些内容。命令diff file1.txt file2.txt
对我没有帮助,
awk 'FNR==NR{a[FNR]=$0;next} {print a[FNR] ORS $0}' Input_file1 Input_file2
输出将如下。
line 1 file 1
line 1 file 2
line 2 file 1
line 2 file 2
说明:添加以上代码的详细说明。
awk ' ##Starting awk program from here. FNR==NR{ ##Checking condition if FNR==NR which will be TRUE when 1st Input_file named file1 is being read here. a[FNR]=$0 ##Creating an array named a whose index is FNR and value is current line value. next ##next will skip all further statements from here. } ##Closing BLOCK for FNR==NR condition here. { ##Block from here will be executed when Input_file2 will be started being read. print a[FNR] ORS $0 ##Printing array a value with current FNR status ORS(new line) and current line value here. } ##Closing BLOCK for above opened one here. ' file1 file2 ##Mentioning Input_file names here.