Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SED to match emails in a sql dump and replace them

Tags:

regex

grep

sql

sed

I am trying to scrub the emails from a SQL dump file, and I could use some advice. I am doing this because I want to send some developers "mostly correct" information, without sharing actual user information. I have a BASH script that loops through line-by-line, so I am trying to do a SED replace on the INSERT statements. I need to iterate through the dumb because I have some other scrubbing stuff, which is working. I have some regex that works (I think), but I cannot seem to get it into SED. The regex of:

'(.*@.*?)'

Will match '[email protected]', but I'm having trouble getting it into SED, and I'm sure that there is a better REGEX. Here's my example line.

'firstname','[email protected]','lastname'

I hope to be able to replace whenever I have an @ between quotes with 'empty@invalid'. Any advice would be greatly appreciated.

like image 554
b degnan Avatar asked Feb 15 '14 16:02

b degnan


1 Answers

Try:

sed "s/'[^@']*@[^@']*'/'empty@invalid'/g"

I've replaced your .* with the more specific [*@']*, which only matches strings which don't have any single-quotes ' or @, which is needed because sed is greedy.

like image 70
Joseph Quinsey Avatar answered Oct 30 '22 16:10

Joseph Quinsey