Skip to main content
1 of 2
Zero
  • 93
  • 5

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:

  1. -o Prints only the matched part.
  2. $ Matches at every ending of line
Zero
  • 93
  • 5