Reno, NV    +1 (800)0 621-0871

Go back

Development | Web Design

G-Edit and Shell to make editing multiple views easier

  |  March 3, 2009

I recently was given a task to change alt tags in ALL of our companies images for better SEO purposes(I do think it won’t impact that much, but I guess they’re thinking any additional impact is better than nothing). I was given an excel file with about 300 images with their current alt tags and their proposed replacements. Yes, another copy and paste task.

What really blows is I don’t have a way of knowing where ALL the instances of the images are, so I had to use my now current favorite shell command to search where a said image is placed in a view:

grep -r -i imagename *

What that does is look which file and line in that file that the imagename string is mentioned. I usually just look for the name itself, and not the extension and the sub-folder, so to look for logo.jpg, I just put

grep -r -i logo *

That returns all the files where logo is mentioned(so I guess you’ll also get non-image results). What’s good about this is that it looks for both the instances when the image was rendered using or <%= image_tag %>

Seeing my first search resulted in 11 hits(I think the options -r -i of grep searches incrementally so it will also look in all sub-folders of the directory you are in), it occurred to me that this might take a while, as I also had to look for all the files, etc. I asked my friend to help in some shell-fu and here’s what we came up with:

gedit grep -r -i -l imagename *

What does this do? Simple, the -l option just lists the filename of the file where imagename was seen(as opposed to including the actual line where it was seen), and the grep enclosed in “ means that the output will be a string…which in turn is sent to gedit. The result? It opens up all the files that contains imagename and that my friends, made my life a wee bit easier in changing the alt tags in all the instances of a said image.

*EDIT: By the way, I know there is an easier way, like maybe replace all instances of said string in all files or something, but I haven’t found out about it yet. If I do, I’ll be sure to make a new post about it :P