How to add duplicate word using regular expression?
Instead of removing duplicate words using regular expression, how do I duplicate a word? My case: I have a list of emails that need to be turn to SQL queries.
buddy@gmail.com
melinda@yahoo.co.uk
terrence12@gmail.com
To:
mysql -e "select * from users where email='buddy@gmail.com" > /tmp/buddy@gmail.com.xls
mysql -e "select * from users where email='melinda@yahoo.co.uk" > /tmp/melinda@yahoo.co.uk.xls
mysql -e "select * from users where email='terrence12@gmail.com" > /tmp/terrence12@gmail.com.xls
So how do I duplicate the email i开发者_StackOverflow中文版n every line?
Note: Each of this query will return more than one row, that's why I'm doing each query individually.
s/(.*)/mysql -e "select * from users where email='\1' > /tmp/\1.xls/
Find Pattern:
(.+)
Replace Pattern:
mysql \-e "select \* from users where email='$1" \> /tmp/$1\.xls\r\n
How it works: (.+): captures a line till its end (before newline character) $1: is the captured group
Note: '-' and '*' are escaped.
You don't need a regex
psedocode:
for each line
set email = line // line should be trimmed of newlines
append 'mysql -e "select * from users where email=\'$email\' > /tmp/$email.xls"' to filename
end
精彩评论