我有一個腳本,它檢查一個文件中的一個文件中的某個文件中的一個關鍵字,看它是否存在於這兩個文件中。但是,在腳本中,grep
從不返回任何已找到的內容,但是在命令行上它已完成。grep裏面的bash腳本沒有找到項目
#!/bin/bash
# First arg is the csv file of repo keys separated by line and in
# this manner 'customername,REPOKEY'
# Second arg is the log file to search through
log_file=$2
csv_file=$1
while read line;
do
customer=`echo "$line" | cut -d ',' -f 1`
repo_key=`echo "$line" | cut -d ',' -f 2`
if [ `grep "$repo_key" $log_file` ]; then
echo "1"
else
echo "0"
fi
done < $csv_file
CSV文件的格式如下:
customername,REPOKEY
和日誌文件如下:
REPOKEY
REPOKEY
REPOKEY
等
我做./script csvfile.csv logfile.txt
嗯,改變這仍然沒有改變我原來的結果,這就像'grep'不在腳本內工作? – Rob 2014-10-16 16:20:19
在'grep'插入'echo'[$ repo_key]''之前,告訴我你的值是多少 – anubhava 2014-10-16 16:22:51