Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I currently have an SQL file filled with insert statements in the form:

 foreign_key, url_one,
 url_two, int_one,
 int_two, int_three) VALUES

I've now realised that the URL strings will need quotation marks around them before I can execute them in MySQL. What command can I use to place quotation marks around the URL string?

I tried to use 'sed' to do it but I couldn't get the command right as I don't completely know the syntax of what I want to achieve:

sed -e "s/(https://).*(\.png)/\"(https://)$1(.png)\"/g" some_sql_file.sql

Running this results in:

sed: -e expression #1, char 12:

unknown option to `s'

Any help would be much appreciated as I want to avoid regenerating the SQL file just to put in the quotation marks if at all possible.

share|improve this question
Remember. Manpages are your friend! :-) – hexafraction Jul 18 '12 at 19:18
up vote 2 down vote accepted

I would use:

sed -e 's@\(https\?://[^,]*\),@"\1",@g' FILE

This looks for a expression starting with http and an optional s followed by ://. Then it takes everything up to the first ,. This expression will be enclosed by ".

share|improve this answer
Thanks for that! How would I get it to write the changes back into the file? – Ross Sep 19 '10 at 22:00
@Rosco: Use the -i option to sed. – Dennis Williamson Sep 19 '10 at 22:54
@Dennis, thanks for that =) works well! – Ross Sep 19 '10 at 23:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.