Here's an very simple example on how to achieve it with grep:
#!/usr/bin/bash result=$(grep -o 'nt$' 'test.txt') if [ "$result" = 'nt' ]; then echo 'Matched !' else echo 'Not found !' fi Explain:
- -o Prints only the matched part.
- $ Matches at every ending of line