The following will print out "chicken", which is expected:
echo "I like chicken" | perl -pe 's|.*(chicken).*|\1|'
Output: chicken
However, the following will print out "I like bacon" even if "chicken" was not matched:
echo "I like bacon" | perl -pe 's|.*(chicken).*|\1|'
Output: I like bacon
How can I avoid the unmatched string from being printed out?
Aucun commentaire:
Enregistrer un commentaire