bash - if grep statement never returning true, always returns 'no such file or directory' -


i have been tasked writing method counts number of red ford fiestas in list of cars, outputs number .txt file, without using -c option in grep

numbercars=0 while read car     echo $car     if grep -e ford\:fiesta.*red $car;         echo "-------done------"         (($numbercars++))     fi done < $userinput echo $numbercars > output/fiesta_red.txt 

the first echo $car works, know while loop working correctly. however, each if grep returns details of car followed "no such file or directory". have tested, each if returning false, regardless of whether pattern i'm searching exists or not

for reference, example of how carslist.txt formatted:

peugeot:206:2000:black:1 ford:fiesta:2000:red:2 

possible solution test pattern

[[ $car =~ ford\:fiesta.*red ]] && echo "-------done------" && (($numbercars++))     

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -