我有两个文件正在比较。寻找确切的词语
Spellingwords.txt =有15个单词,每行一个单词。
Userwords.txt =用户输入。一次一个字。
结果
Spellingwords.txt(左栏)
Userwords.txt(右栏)
water water
gas gas
boy BOY
这里发生的是,结果应为0 - 但它返回1. BOY一词算作拼写错过。
我如何接受 BOY 这个词与 boy 相同?
这是我目前的代码。
wword="$(awk 'NR==FNR{a[$0];next}{if(!($0 in a))c++;}END{print c+0}' spellingwords.txt /tmp/userwords.txt)"
答案 0 :(得分:2)
您可以使用tolower
函数以不区分大小写的方式比较单词:
$ awk 'NR==FNR{a[tolower($0)];next}{if(!(tolower($0) in a))c++;}END{print c+0}' Spellingwords.txt Userwords.txt
0
答案 1 :(得分:1)
稍有改进
awk 'tolower($1)!=tolower($2){c++} END{print c+0}' <(paste list1 list2)
答案 2 :(得分:0)
如果IGNORECASE
为awk
或包含此选项的其他类型check this link,您可以使用GNU
选项。
另一种选择是使用diff
(不区分大小写选项-i
)而不是awk
,如果可以的话。例如,diff -i file-1 file-2
输出不同文件中的行(忽略大小写),插入符号显示每个特定行所属的文件。 --side-by-side
diff
选项会在单独的列中逐行输出每个比较文件,并标记不匹配的行。 diff
也会返回&#34; 0&#34;当文件没有区别时作为退出代码。
答案 3 :(得分:0)
在将所有单词相互比较之前,将所有单词设为小写:
<?php
$sql = "SELECT *, IF(t.cnt IS NULL, 0, t.cnt) AS c
FROM files LEFT JOIN
(SELECT count(*) AS cnt, fileId , schoolName FROM user_logs GROUP BY fileId) AS t
ON files.fileId = t.fileId
ORDER BY fileName DESC";
$result = mysqli_query($con,$sql);
while ($row = mysqli_fetch_assoc($result)) {
$fileId = $row['fileId'];
$num_row = $row['c'];
echo "<tr>";
echo "<td>".$row['fileName']."</td>";
echo "<td><a data-toggle='modal' href='#".$row['fileId']."'>". $num_row ." / 2 Schools Clicked</a></td>";
echo "</tr>";
echo '<div class="modal fade" role="dialog" id="'.$row['fileId'].'">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">'. $row['fileName'] .'</h4>
</div>
<div class="modal-body">';
// Here I want to display the schools that clicked the file from use_logs
echo '<p>Name of schools that clicked the file :</p>
<ul>
<li>'.$row['schoolName'].'</li>
<ul>';
// And here i want to display the school names that doesn't clicked the file yet
echo '<p>Name of schools that doesn`t clicked the file yet:</p>
<ul>
<li>'.$row['schoolName'].'</li>
<ul>';
echo '</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>';
}
?>