2015-05-01 45 views
0

bash下面的文件(getCSV)被curl下載並且用戶輸入了一個id,該id在被下載的getCSV文件中被搜索。目前curl的作品和用戶可以輸入ID,但然後關閉bash。我想要的是,當在屏幕上輸入一個ID時,顯示信息「正在搜索,請稍候」,並且如果找到匹配,則在屏幕上顯示「在...行中找到匹配」並且文件被寫入。bash搜索文件並基於輸入創建新文件

input=$id  
while read -r line 
do 
if [ -n "$id" ]; then 
echo "match found in line $id"|sed 's/:.*//' 
echo "$result"|sed 's/[^:]*://' >> match.txt 
else 
echo "no match found" 
fi 
done 
+0

那麼問題是什麼? – Jahid

+0

bash在沒有打印任何錯誤消息的情況下關閉? –

+0

是的,bash關閉時沒有在屏幕上打印任何消息,但創建了match.txt文件。謝謝:) – Chris

回答

1

所以聽起來:目錄如果沒有找到匹配,則

所以類似的東西顯示在屏幕上謝謝:)

#!/bin/bash 

printf "establishing connection and downloading file, please wait" 
cd 'C:\Users\cmccabe\Desktop\wget' 
curl -# -o getCSV.txt http://xxx.xx.xxx.xxx/data/getCSV.csv 


printf "Download complete, what is the id of the NGS patient: "; read id 
[ -z "$id" ] && printf "\n No ID supplied. Leaving match function." && sleep 2 && return 
[ "$id" = "end" ] && printf "\n Leaving match function." && sleep 2 && return 

result=`grep -n "${id}" getCSV.txt` 
if [ -n "$result" ]; then 
echo "match found in line $result"|sed 's/:.*//' 
echo "$id"|sed 's/[^:]*://' >> match.txt 
else 
echo "no match found" 
fi 

代碼編輯。就像你想等待用戶輸入一樣像read varname

+0

所以像原代碼中的代碼編輯?謝謝 :)。 – Chris

+0

取決於你在做什麼;如果你只希望它在執行代碼後等待一次,那麼你可以在底部進行讀取操作,並且在完成上述所有邏輯之後,等待有人擊中返回/輸入。 – Seeds

+0

我不確定'read varname'是否會在第一篇文章中做所有事情,但它肯定會有所幫助。謝謝 :) – Chris