Here's an very simple example on how to achieve it withusing both grep and sed:
#!/usr/bin/bash result=$(grep -o 'nt$' 'test'Output.txt' | sed '$!d') if [ "$result" = 'nt' ]; then echo 'Matched !' else echo 'Not found !' fi Explain:
- -o Prints only the matched part.
- $ Matches at every ending of line
- -o Prints only the matched part.
- $ Matches at every ending of line
- '$!d' Deletes all lines except the last one.