Working with strings

·

1 min read

Table of contents

Grep

grep x searches for x and outputs that line grep -i x for case Insensitivity grep -v x outputs all line Excluding x grep -n x outputs with the line number grep -c x outputs the number of occurrences of x grep x * looks for x in all directories grep -r x /path looks for x recursively in the path



Regex

grep, sed, awk can use regex java, py, js etc can use regex


a* Zero or more occurrences of "a" Example fooa*bar matches

fooaaaabar
fooabar
foobar
fooaabar

. the dot/ single wildcard represents any ONE character in a single position

Example foo.bar matches

fooabar
fooxbar
foocbar

and not "foobar" or "fooxybar" or "baryfoo"


.* for ANY CHARACTER having ZERO OR MORE OCCOURENCES Example

[Pasted image 20230118161705.png]