我基本上正在处理两个文件(文件1和文件2)。目标是编写一个脚本,如果文件1、2中的1、2、3列匹配,则从文件1中提取行。这是我一直在玩的代码:
awk -F'|' 'NR==FNR{c[$1$2$3]++;next};c[$1$2$3] > 0' file1 file2 > filtered.txt
ile1和file2都看起来像这样(但还有更多列):
name1 0 c
name1 1 c
name1 2 x
name2 3 x
name2 4 c
name2 5 c
我提供的awk代码未产生任何输出。任何帮助,将不胜感激!
答案 0 :(得分:1)
您的分隔符不是管道,请尝试此
$ awk 'NR==FNR {c[$1,$2,$3]++; next} c[$1,$2,$3]' file1 file2 > filtered.txt
或
$ awk 'NR==FNR {c[$0]++; next} c[$0]' file1 file2 > filtered.txt
但是,如果您要整行匹配,grep
$ grep -xFf file1 file2 > filtered.txt
答案 1 :(得分:1)
foreach ($json->data as $row) {
if (!in_array($row->guestEmail, $emails)
&& date('Y-m-d', strtotime($row->endDate))== date('Y-m-d')) {
$guests[] = array(
'FirstName' => $row->guestFirstName,
'LastName' => $row->guestLastName,
'email' => $row->guestEmail,
'country' => $row->guestCountry,
'check-in_date' => $row->startDate,
'check-out_date' => $row->endDate,
);
$emails[] = $row->guestEmail;
}
}