Thursday, July 23, 2015

Grep between two words in string

Say from the string "Age: = 24 years", you want to extract the value 24. Grep can be used to search for a pattern between two words. Here is the grep command for that:
echo "Age: = 24 years" | grep -P -o '(?<=Age: = ).*(?= years)'

No comments:

Post a Comment