In the bash
when the user inputs an id to search for the bash
currently closes, and if a match is found outputs a new file (match.txt). Is it possible to have not close the bash
but rather, on the screen "searching for match" and if a match is found "match found in line.." is displayed and written to match.txt else "no match found" is displayed on the screen and no file is written. Thank you :).
The code below downloads a getCSV file then the user enters an id and that input is used to search the getCSV file. Currently, the last part is not working. I have added a loop and modified so other parts of the code with no luck.
#!/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 && exit 1
printf "searching, please wait"
result=`grep -n "${id}" getCSV.txt`
while read -r line
do
if [ -n "$result" ]; then
echo "match found in line $result" >> match.txt
else
echo "no match found"
done
fi