我有两个文件,其中包含文本和说明:
**File1.txt:**
"ID1" "Text text text text" "True"
"ID2" "Text text text text" "True"
"ID3" "Text text text text" "True"
"ID4" "Text text text text" "True"
**File2.txt:**
"ID1" "Description description description" "True"
"ID2" "Description description description" "True"
"ID6" "Description description description" "True"
"ID7" "Description description description" "True"
"ID3" "Description description description" "True"
我想只写这些描述,其ID与文本相同:
**File3.txt:**
"ID1" "Description description description" "True"
"ID2" "Description description description" "True"
"ID3" "Description description description" "True"
另一个文件必须包含文本,其中包含来自file3.txt
的ID**File4.txt**
"ID1" "Text text text text" "True"
"ID2" "Text text text text" "True"
"ID3" "Text text text text" "True"
如您所见,我想比较两个文件并仅使用相同的ID编写行。我想在.Bat文件中使用AWK软件来做到这一点,但我真的不知道如何开始。 引号“ID”“text”“True”之间有标签。
提前致谢
答案 0 :(得分:0)
awk one-liner一次性生成两个文件:
awk 'NR==FNR{a[$1]=$0;next}$1 in a{print a[$1]>"file4.txt";print}' file1 file2 >file3.txt
如果分隔符为<TAB>
awk -F'\t' 'NR==FNR.....'