我有这两个文件:file1
2537
1279
1075
12799
1474
135441
1260
1169
1281
10759
和文件2
1070,1279960511,BR,USA,UNITED STATES
1278,1279960511,US,USA,UNITED STATES
1279,1279960527,CA,CAN,CANADA
1289,1279967231,US,USA,UNITED STATES
2679,1279971327,CA,CAN,CANADA
1279,1279971839,US,USA,UNITED STATES
1279,1279972095,CA,CAN,CANADA
1279,1279977471,US,USA,UNITED STATES
127997,1279977983,CA,CAN,CANADA
127997,1279980159,US,USA,UNITED STATES
127998,1279980543,CA,CAN,CANADA
107599,1075995007,US,USA,UNITED STATES
107599,1075995023,VG,VGB,VIRGIN ISLANDS, BRITISH
107599,1075996991,US,USA,UNITED STATES
107599,1075997071,CA,CAN,CANADA
我想:对于 file1 的每个条目,通过 file2 的第一列,当该列中的值大于“file1”元素时,然后返回 file2 的第三个元素我尝试了很多方法,但没有一个有效我要么得到一个空文件或打印的内容与我预期的不同我最后一次尝试是:
awk -F, '
BEGIN {FS="," ; i=1 ; while (getline < "file2") { x[i] = $1 ; y[i] = $3 ; i++ }}
{ a[$1] = $1 ; h=1 ; while (x[h] <= a[$1]) { h++ } ; { print y[h] }}' file1
但这永远运行它不会停止也不会给我任何帮助plzzz这已经杀死我好几天了,我放弃了谢谢
期望的输出:
#this is a comment and i ll write file 2 as if it was a matrix
because file1[1] > file2[1,1] ... and file1[1] > file2[2,1] .... and file1[1] > file2[3,1] ... and file1[1] > file2[4,1] but file1[1] < file2[5,1] ... then print file2[4,3] ... which is "US"
now go to file1[2] :
file[2] > file2[1,1] ... and file1[2] > file2[2,1] ... but file1[2] <= file2[3,1] ... then print file2[3,3]
总之我想打印:“第一行的第三个元素(col)(来自file2)file1元素首先变成>下一行的第一个元素(file2)