awk one-liner generates two files in one shot:
awk 'NR==FNR{a[$1]=$0;next}$1 in a{print a[$1]>"file4.txt";print}' file1 file2 >file3.txt
if the separator is <TAB>
awk -F'\t' 'NR==FNR.....'
문제
I have two files which contains Texts and Descriptions:
**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"
and I want to write only these descriptions which has the same IDs as Texts:
**File3.txt:**
"ID1" "Description description description" "True"
"ID2" "Description description description" "True"
"ID3" "Description description description" "True"
another file must contain texts that have IDs from file3.txt
**File4.txt**
"ID1" "Text text text text" "True"
"ID2" "Text text text text" "True"
"ID3" "Text text text text" "True"
As you can see, I want to compare two files and write lines with the same id only. I want to use AWK software in .Bat file to do this but i don't really know how to start. There're tabs between quotes "ID" "text" "True".
Thanks in advance
해결책
awk one-liner generates two files in one shot:
awk 'NR==FNR{a[$1]=$0;next}$1 in a{print a[$1]>"file4.txt";print}' file1 file2 >file3.txt
if the separator is <TAB>
awk -F'\t' 'NR==FNR.....'