Finding strings in a file using regex and grep in Linux -
i trying find proper regexes use grep command on file text.txt.
question
find occurrences of words in text have substring ad, bd, cd, dd, ed.
find occurrences of numbers > 100
find occurrences of numbers > 100 contain digit 0 or 5
my approach
grep -io '[a-e]*d' textprints words proper substrings, doesn’t print whole string/word.
ad d d ed d d ed d d d d ed d dgrep -io '[199][1-9]*' texti believe way off on regex, still prints correct result.
1973 197 17775grep -io '[05][1-9]*' textthis continuation of 2., don’t understand 2. part in 3., believe have string containing digit 0 or 5 correct.
0 0 0 5
a) find occurrences of words in text have substring ad, bd, cd, dd, ed.
grep -ow '.*\(a\|b\|c\|d\|e\)d.*' text or
egrep -ow '.*(a|b|c|d|e)d.*' text b) find occurrences of numbers > 100
grep -ow '[1-9][0-9][0-9]\+' text c) find occurrences of numbers > 100 contain digit 0 or 5
grep -ow '[1-9][0-9][0-9]\+' text | grep '\(0\|5\)' or
grep -ow '[1-9][0-9][0-9]\+' text | egrep '(0|5)' i'm using option -o output every match on it's own line , not whole line pattern found , option -w specifies before , after match should word boundary.
Comments
Post a Comment