Mar 052013
 

I’ve discovered the fantastic yearbox plugin for Dokuwiki, which is superb for my electronic lab notes.  However, implementing it neatly required me to change the filename of every log entry from the last few years.  In my old Dokuwiki system, each log had a filename like

…/pages/log/2013/01/07.txt

I needed to keep the directory structure, but change each filename from two digits to the form “2013-01-07-ljr.txt”.

It turns out to be fairly straightforward with some clever bash tricks.  I changed into the log directory and used this command:

 for i in `find -name '??.txt'` ; do mv $i ${i%/*}/${i:2:4}-${i:7:2}-${i:10:2}-ljr.txt; done

Here the first part finds all files with names of the form “??.txt”.  Then each file is renamed with the “mv” command.  The ${i%/*} gives the file path with everything after the last “/” removed (ie it gives the subdirectory of the file).  Then the rest of the parentheses give extracted parts of the filepath string.

All files stayed in their own directories, and were renamed with additional information from their directory path.  Easy!  Well, not unless you know the details of string manipulation in bash – which I don’t.  I found enough information to do this after looking here and here.

Mar 052013
 

I often use the “-” symbol to separate parts of a long filename.  For example, my photos are systematically named things like “20130214-1123-34_some_event.jpg”.  For filename maintenance I regularly use the rename command, which allows me to do things like

rename some another *

which would replace the word “some” with the word “another” for every filename in the current directory.  When I need to replace a chunk of filename starting with the “-” character, the rename command thinks I’m passing it an option.  I’ve just found a helpful answer that shows how the “end-of-options” signal fixes this problem.  This signal is simply a double dash “–“.  For example, this command

rename — -11 -10 *

would change the timezone on a bunch of photo filenames.

Feb 022010
 

At ASA Convention, a number of us took many photographs.  Late on the last night, I helped compile the highlights into a souvenir data DVD.  Using the nifty little exiv2 utility, I was able to adjust the image timestamps and retrospectively synchronise the clocks in every camera.  This makes for very enjoyable photo browsing, as you can view chronologically regardless of which camera was used.

Unfortunately I was too rushed to place attribution in the filenames, and so it is not obvious who took each photo.  Luckily we all used different camera models, and that information is still present in the exif metadata.  I used this to split the photos into directories and embed the photographer in both metadata and filename.

I was shooting on my Nikon D200, and so was able to separate my photos by:

for ii in *.jpg; do if grep -q "NIKON D200" $ii ; then mv $ii lachlan/ ; fi ; done

This says: for each jpg file, check if it contains “NIKON D200” in the exif metadata and if it does then move it to the subdirectory lachlan/

All you need to do is find the camera model string to search for (my friends with Canons had things like “Canon EOS 30D”).  Now I’m going to append photographer names to the filenames, and then return them to their original chronological directories.

[For Facebook Notes readers: this post is redirected from my personal website lachlan.rogers.name]

Nov 102009
 

I jotted this down a year ago when I needed to produce a set of handout notes for a 3rd year physics lecture I took. Just last week, after taking a similar set of lectures, I wanted to find it but couldn’t. Murphy’s Law has come into effect, and my jotted note has turned up now that my need for it has passed.

The Beamer class for LaTeX is a great way to produce very nice presentation slides with useful features such as automatic progress markers and internal hyperlinks. Being LaTeX, it is also possible to completely change the output formatting by simply altering certain document settings. This allows me to produce slides that have black backgrounds for better projection onto a screen, and then change a single line (specifying the colour theme) to get a white-background version optimised for printing on paper.

To make it even more efficient to print, I used the following command to fit 3 slides to an A4 page:

pdfnup --frame false --nup 1x3 --paper a4paper --orient auto --pages all --trim "0 0 0 0" --delta "1cm 1cm" --offset "0 0" --scale 0.91 --turn true --noautoscale false --openright false --column false --columnstrict false --tidy true --outfile main3up.pdf main.pdf