Extract email addresses from text file using regex with bash or command line

后端 未结 4 1340
误落风尘
误落风尘 2020-12-15 08:32

How can I grep out only the email address using a regex from a file with multiple lines similar to this. (a sql dump to be precise)

Unfortunately I cannot just go b

4条回答
  •  萌比男神i
    2020-12-15 09:08

    The best way to handle this is with a proper CSV parser. A simple way to accomplish that, if it's a one-time task, is to load the CSV file into your favorite spreadsheet software, then extract just the email field.

    It is difficult to parse CSV with a regex, because of the possibility of escaped commas, quoted text, etc.

    Consider, the following are valid email addresses, according to Internet standards:

    • foo,bar@gmail.com
    • foo"bar@gmail.com

    If you know for a fact that you will never have this sort of data, then perhaps simple grep and awk tools will work (as in @anubhava's answer).

提交回复
热议问题