Home > Coding > Eclipse search and destroy

Eclipse search and destroy

October 11th, 2007 Leave a comment Go to comments

Eclipse (Popular IDE) offers the possibility to do ‘search and replace’ with regular expressions. Today this came in quite handy as I had to change a large amount of sql insert statements into sql update statements.

Although loading the file of 4MB took quite some time (probably because of the syntax highlighting eclipse was trying to apply) the file could be loaded. After that I opened the search & replace option from the menu and started creating something that looked like a regular expression.

Here is one line of the original input:

INSERT INTO MEDIA (MEDIA_ID,UPLOADFILE_FILENAME,UPLOADFILE_FILESIZE,UPLOADFILE_HEIGHT,UPLOADFILE_WIDTH)
VALUES (1579,'1579.jpg',1095082,2575,4075);

This is the regex I came up with:

.*?\(.*?\((\d+),(.*?),(\d+),(\d+),(\d+)\)\;

I had it replaced with:

update MEDIA
set UPLOADFILE_FILENAME=$2, UPLOADFILE_FILESIZE=$3,UPLOADFILE_HEIGHT=$4,UPLOADFILE_WIDTH=$5
where MEDIA_ID=$1;

Worked like a charm. The lines now looked like this:

UPDATE MEDIA
SET UPLOADFILE_FILENAME='1579.jpg', UPLOADFILE_FILESIZE=1095082,UPLOADFILE_HEIGHT=2575,UPLOADFILE_WIDTH=4075
WHERE MEDIA_ID=1579;

Seems like abracadabra? Well it is, since the outcome was magical. :)

Categories: Coding Tags:
  1. No comments yet.
  1. No trackbacks yet.