My objective is to match email addresses that belong to the Yahoo! family of domains. In *nix systems (I will be using Ubuntu), what are the benefits and drawbacks to any one of these methods for matching the pattern?
And if there is another, more elegant solution that I haven't been capable of imagining, please share.
Here they are:
grep
with option -i
:grep -Ei "@(yahoo|(y|rocket)mail|geocities)\.com"
grep
:tr [:upper:] [:lower:] < /path/to/file.txt | grep -E "@(yahoo|(y|rocket)mail|geocities)\.com"
grep -E "@([yY]ahoo|([yY]|[rR]ocket)[mM]ail|[gG]eo[cC]ities)\.[cC][oO][mM]" /path/to/file.txt
Case Insensitive Search By default, grep is case sensitive. This means that the uppercase and lowercase characters are treated as distinct. To ignore case when searching, invoke grep with the -i option (or --ignore-case ).
Grep is case-sensitive by default hence it shows the perceptibility of both upper and lower cases in the file.
grep -i
turned out to be significantly slower than translating to lowers before grepping, so I ended up using a variation of #2.
Thanks @mike-w for reminding me that a simple test goes a long way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With