我想逐行读取文件并测试第二个文件中的行是否存在于$ 3中然后打印$ 0否则打印该行。 我的第一个文件包含这样的值:" 00 01 03 。 。 80 A1 A2 A3 。 。 B5"
脚本正常工作到80,但当该行成为字符串时,它不起作用。这是代码
while read -r line
do
cat file2.txt | awk '
BEGIN { FS="."
test=0
}
('"$line"'==$1) {test=1
result=$0}
END{
if (test==1) { print result}
else { print '"$line"'}
}
'
done < file1.txt'
答案 0 :(得分:0)
这不是 $sql = "Select * FROM modems";
$query = $db->prepare( $sql );
$query->execute();
$results = $query->fetchAll( PDO::FETCH_ASSOC );
$return = "Select SUM(maddress) FROM modems";
$query = $db->prepare( $return);
$query->execute();
?>
<!---Table class that creates a table--->
<table class="table">
<caption>Modem Results Page</caption>
<tr>
<th>Mac Address</th>
<th>Modem Model Number</th>
<th>Date</th>
<th>Reported Problem</th>
<th>Good or Bad</th>
<th>Initials</th>
<th>Times Returned</th>
</tr>
<input type='button' value='Return to Modems Page' onclick="location.href='modems.php'"><br><br>
<!---Populates data in the table--->
<?php foreach( $results as $row){
echo "<tr><td>";
echo $row['maddress'];
echo "</td><td>";
echo $row['mmodel'];
echo "</td><td>";
echo $row['date'];
echo "</td><td>";
echo $row['mproblem'];
echo "</td><td>";
echo $row['good_bad'];
echo "</td><td>";
echo $row['initials'];
echo "</td><td>";
echo $row['SUM(maddress)'];
echo "</td>";
echo "</tr>";
}
?>
</table>
的正确方法。这样做的惯用方法是
awk
请注意,首先提供第二个文件。另外你提到你比较3美元但是代码说的是1美元。
答案 1 :(得分:0)
@karakfa
file2的:
00
01
02
A1
A2
B1
B2
file 1
B2.9.75.lkf
B1.69.874.cds
00.364.6478.abc
A1.635.7452.cds
01.36.3214.vcd
我想要那样的输出
00.364.6478.abc
01.36.3214.vcd
02.not found
A1.635.7452.cds
A2.not found
B1.69.874.cds
B2.9.75.lkf
它遵循文件2的顺序,如果它不存在则写入未找到
答案 2 :(得分:0)
@ M122015:尝试:
awk 'FNR==NR{q=$1;sub(/.*/,"",$1);sub(/^[[:space:]]+/,"");gsub(/ /,".");A[q]=$0;next} ($0 in A){print $0 "." A[$0];next} !($0 in A){print $0".not found."}' FS="." Input_file1 Input_file2