_____________________________________
Search a letter in a string using grep
_____________________________________
$ string="unix-bash 2389"
$ character="-"
$ echo $string | grep -q "$character" && echo "found" || echo "not found"
found
$ character="@"
$ echo $string | grep -q "$character" && echo "found" || echo "not found"
not found
_______________________________________
Search a letter in a string using awk
_______________________________________
$ character="@"
$ echo $string | awk -vc="$character" '{if(gsub(c,"")) print "Found";else print "Not Found"}'
Not Found
$ character="-"
$ echo $string | awk -vc="$character" '{if(gsub(c,"")) print "Found";else print "Not Found"}'
Found

No comments:
Post a Comment