I am iterating through a text file line by line in bash and printing out the word segments that match the relevant regex pattern. This process is done by accepting the text file as an argument. My code works fine but at the end, in the last line, an unwanted output gets printed. I am new to bash and I have no idea why this is happening. Shown below is my code:
#!/bin/bash
pat='[a-z][a-zA-Z0-9_]*\.png'
while IFS='' read -r line || [[ -n $line ]];do
echo $line | grep -o -P $pat
done < "$1"
shown below is the output(the unwanted line is the highlighted one):
I want to get rid of this last line of unwanted output.