Monthly Archives: February 2008

zero-width negative look-ahead assertion

Currently I need to do some bulk transformation of some file names. I have, say, 3 file names: 2.640-849.0.jpg, g2650ohr.jpg, and k2.26mr.jpg (so these are treated as three separate strings) I want a (hopefully) single regex to substitute all of the . (periods) with - (dashes) except for the .jpg extension. A first draft would be s/\./-/g but [...]
Posted in programming, sysadmin | Leave a comment

use env to test scripts for cron and monit

I’ve used /usr/bin/env for years but I just realized today that it can be very useful for testing processes that are run with cron or monit. env has a nice option for clearing out all of the environment variables: -i, --ignore-environment - start with an empty environment Now you can try to run your script [...]
Posted in sysadmin | Leave a comment

increment the number in a file

Lets say you have a file called REVISION which contains a single number. If you want to increment the number in that file you could run the following command: let rev=`cat REVISION`+1 && echo $rev > REVISION Wrap that up as a nice shell script and you get a nice increment command: #!/bin/bash let rev=`cat $1`+1 && echo $rev [...]
Posted in sysadmin | Leave a comment