Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

 INSERT INTO
 database.table(primary_key,
 foreign_key, url_one,
 url_two, int_one,
 int_two, int_three) VALUES
 (266,7,https://some.url.com/image_one.png,https://some.url.com/image_two.png,266,1440,900);

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
add comment

1 Answer

up vote 1 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? –  Rosco 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! –  Rosco Sep 19 '10 at 23:30
add comment

Your Answer

 
discard

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.