I want to search a string in a file, and after much searching this website, I ended up using grep
in and if
statement. However, things aren't working as I expect them, even though I followed all the instructions I found on other related posts. Here's my code.
echo "Enter dicounter number"
read string1
echo "Enter side with LEDs"
read string2
if grep -q "dicounter_$string1_from_$string2" MasterFile.txt; then
echo "dicounter_$string1_from$string2 already exists in MasterFile."
else
{ (a bunch of stuff to make the transmitter operate) }
fi
The primary problem I think is with the way I am reading in my command line arguments.