I am writing a bash script which accepts a list of CSV files as arguments and outputs e-mail addresses only found in the first file. To accomplish this, for each record in the first CSV file I look up the e-mail address field and read its contents into a shell variable. Then, I use
grep -iE with the following regular expression to look up the e-mail address just found in all the remaining files, making sure that it is not a substring (e.g. [email protected] is not the same as [email protected]), and allowing it to be at the beginning or end of a record:
A problem with this approach is that e-mail addresses contain dots which have a special meaning in regular expressions. My questions are:
- How can I avoid this problem in an elegant way?
- How can I avoid this problem in a more general context, e.g. when the value to look up is not an e-mail address but some free text and might contain other special characters as well?