brew install grep
and command is called ggrep instead of grep.
Get the substring between two words
echo "<person><name>abc</name></person>" | grep -o -P '(?<=<name>).*(?=</name>)'
Output should be:
abc
Count the length of substring
echo "<person><name>abc</name></person>" | grep -o -P '(?<=<name>).*(?=</name>)' | wc -c
Output should be:
3
Count substring lengths for each line
cat multi-lines.txt | while read line; do echo $line | grep -o -P '(?<=<name>).*(?=</name>)' | wc -c; done
No comments:
Post a Comment