Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

match two file passing input as parameter

Status
Not open for further replies.

darioit

IS-IT--Management
Sep 23, 2010
3
0
0
IT
I try to wrote a program using awk (in Windows env) that reads an inp.txt file and for each record searches for corrispondent line present in file history.txt starting in history.txt from position 21 by 55 characters. If found, print the full matched history.txt line

inp.txt
AAA_BBB_CCC_77_1c2a39c6-199e-4f4f-9971-32d3f7fdb74f.zip
AAA_BBB_DDD_77_1c2a39c6-199e-4f4f-9971-32d3f7fdb74f.zip

history.txt
2023-01-01 12.00.00 AAA_BBB_EEE_77_1c2a39c6-199e-4f4f-9971-32d3f7fdb74f.zip
2023-01-01 12.00.00 AAA_BBB_CCC_77_1c2a39c6-199e-4f4f-9971-32d3f7fdb74f.zip
2023-01-01 12.00.00 AAA_FFF_CCC_77_1c2a39c6-199e-4f4f-9971-32d3f7fdb74f.zip

I wtote this simple script
gawk "NR==FNR {history_lines[substr($0,21,55)]=0; next} {search_string=($1)} search_string in history_lines" history.txt inp.txt
gawk "NR==FNR {search[substr($0,21,35)]; next} {for (s in search) if(index($0, s)) {print; break}}" inp.txt history.txt
gawk "NR==FNR {search[substr($0,21,35)]; next} {for (s in search) if(index($0, s)) {print; delete search; break}}" inp.txt history.txt
If there's some error please tell me

My question is how can I pass a single row as parameter?

Thank you in advance

 
I don't know if it's good or not because the substring you're looking for is present in all records of inp-file and all records of the history-file
(i.e.: substr($0,21,35) = 9c6-199e-4f4f-9971-32d3f7fdb74f.zip)
Then which line from inp-file corresponds with which line of history-file ?

Wasn't it rather meant so, that you should search for the whole line of inp-file instead?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top