Pages

lundi 13 février 2012

test if a stri exists in another string; get last few letters

---to test if str exists in $mystring:
echo $mystring | awk '{print index($0, "str")}'" searches the $mystring variable for an occurrence of "str" in the string's value.


if exists, return 1, otherwise 0



--- to get the last few letters from a string:
 awk '{ print substr( $0, length($0) - 1, length($0) ) }'   input_file

Aucun commentaire:

Enregistrer un commentaire