Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i get "sed" to delete everything else but email address.

Tags:

sed

how do i get "sed" to delete everything else but email address.

db dump: someusername ::: kRW...0fPc ::: $2a$10$...aucvkDt86 ::: [email protected]
like image 581
NVK Avatar asked Nov 29 '22 04:11

NVK


1 Answers

Does it have to be sed? What about grep? Here's how to use it with the regex you gave:

$ cat dbdump.txt 
db dump: someusername ::: kRW...0fPc ::: $2a$10$...aucvkDt86 ::: [email protected]
another line with two e-mail addresses <[email protected]> on it -- [email protected]

$ grep -EiEio '\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b' dbdump.txt
[email protected]
[email protected]
[email protected]

The -o flag prints only the matching portions, i.e. just the e-mail addresses. -i makes the matching case insensitive. It even finds multiple e-mail addresses on the same line.

Edit: I couldn't resist the -EiEio. I suppose grep -Eio or egrep -io would also work...

like image 177
John Kugelman Avatar answered Dec 05 '22 16:12

John Kugelman