2015-05-01 42 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