我有一个包含以下数据的File_1.txt。
1234
2567
第二个文件File_2.txt中包含以下数据。
2015-10-30,1234,zxcfgdk,kyfz
2015-10-30,2567,askjfkj,aaaa
2015-10-30,8888,bsjfjah,iojk
我想将File_1.txt数据与File_2.txt的column2数据进行比较。如果匹配,则将整个File_2.txt行重定向到单独的文件。而那些与其他文件不匹配的那个。
用Google搜索了很多页面。但没有任何帮助。
谢谢!
答案 0 :(得分:1)
使用 TimerElapsedHandler handler=function;
ThreadPoolTimer.CreatePeriodicTimer(handler, TimeSpan.FromSeconds(30));
async private void function(ThreadPoolTimer timer)
{
URL_log_string = device_id_string + "," + UTCdatetime + "," + lng + "," + lat + "," + speed + "," + heading + "," + alt + "," + "," + battery_level + "," + accuracy + "," + 1 + "," + "," + 0;
//Locally log storage
Log_Class_Object.Save_Data_in_Log("Panic Sent ", URL_log_string);
URL_log_string = "";
}
:
awk
使用$ cat s.awk
BEGIN { FS="," }
NR==FNR { a[$1]; next }
$2 in a { print > "matched.txt" }
!($2 in a) { print > "missing.txt" }
$ awk -f s.awk f1 f2
$ cat missing.txt
2015-10-30,8888,bsjfjah,iojk
$ cat matched.txt
2015-10-30,1234,zxcfgdk,kyfz
2015-10-30,2567,askjfkj,aaaa
:
另一种可能性就是使用grep,但是你需要确保file1中的值永远不会出现在field2之外的file2中(字分隔):
grep