I have a file that shows the output of ls
e.g.
/home/john/A_2014.jpg /home/john/B_2014.jpg /home/john/C_2014.jpg /home/john/D_2014.jpg now I want to use this output to write an insert script for mysql. I achieved to enter at the beginning and the end of every line the necessary code so the file actually looks like:
INSERT INTO myimages (name,picture) values ('#name',LOAD_FILE('/home/john/A_2014.jpg')); INSERT INTO myimages (name,picture) values ('#name',LOAD_FILE('/home/john/B_2014.jpg')); INSERT INTO myimages (name,picture) values ('#name',LOAD_FILE('/home/john/C_2014.jpg')); INSERT INTO myimages (name,picture) values ('#name',LOAD_FILE('/home/john/D_2014.jpg')); Is there a way to substitute #name with the string that occurs before _2014.jpg so that the final output looks like
INSERT INTO myimages (name,picture) values ('A',LOAD_FILE('/home/john/A_2014.jpg')); INSERT INTO myimages (name,picture) values ('B',LOAD_FILE('/home/john/B_2014.jpg')); INSERT INTO myimages (name,picture) values ('C',LOAD_FILE('/home/john/C_2014.jpg')); INSERT INTO myimages (name,picture) values ('D',LOAD_FILE('/home/john/D_2014.jpg')); Unfortunately there are to many lines to do this by hand. Thanks for your help.