tags:

views:

29

answers:

2

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.

[email protected]
[email protected]
[email protected]

To:

mysql -e "select * from users where email='[email protected]" > /tmp/[email protected]
mysql -e "select * from users where email='[email protected]" > /tmp/[email protected]
mysql -e "select * from users where email='[email protected]" > /tmp/[email protected]

So how do I duplicate the email in every line?

Note: Each of this query will return more than one row, that's why I'm doing each query individually.

+1  A: 

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 
Byron Whitlock
+2  A: 
s/(.*)/mysql -e "select * from users where email='\1' > /tmp/\1.xls/
Charles
+1 yummy Perl/sed....
Byron Whitlock
can you please example how \1 will substitute email address?
Ayaz Alavi