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

后端 未结 4 1351
误落风尘
误落风尘 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条回答
  •  清歌不尽
    2020-12-15 09:08

    You can solve it using python with the help of the built-in csv module and the external validators module, like this:

    import validators
    import csv
    import sys
    
    with open(sys.argv[1], newline='') as csvfile:
        csvreader = csv.reader(csvfile)
        for row in csvreader:
            for field in row:
                if validators.email(field):
                    print(field)
    

    Run it like:

    python3 script.py infile
    

    That yields:

    cgreen@blah.com
    

提交回复
热议问题