log sampling

A little Perl snippet for sampling a log file (or whatever): grep something myfile | perl -n -e ‘print if $. % 12 == 1;’

testing vs. documentation

I have made some progress on my automatic ipod transfer script The first step is to set Nautilus (that’s the file browser in the Gnome desktop) preferences, since it is the program which deals with automatically mounting media. So in Nautilus->Edit->Preferences->Media I set the ‘Media Handling’ for ‘Music Player’ to run a script of my […]

how to loop by line in bash

ORIGIFS=$IFS; IFS=`echo -en "\n\b"`; for line in $(cat my_list_file); do echo $line; done; IFS=$ORIGIFS

web testing with curl

It happened again. You have an annoying bug with your Java web application, and you’re stepping through with your debugger, and… whoops! looks like you just missed an important line. You fire off the same request again, so you go back to your browser and go through the steps to that point – did I […]

bash twitter

There are probably lots of variants out there. In fact mine is largely copied from here Inspired by BLT #!/bin/bash # a twitter client (uses .netrc for auth)   confdir=~/.bt seenfile=$confdir/seen feedstyle=$confdir/btfeed.xsl   if [ "$1" == "-h" ]; then echo " use: $(basename $0) -h | [ tweet ]" echo " -h help" echo […]

dns323 podcast downloader

Our server box is taking over lots of little download tasks for us. The next thing I wanted it to do is automatically get podcasts. Being a Ruby fan I knocked up a little script – it’s handy having RSS reading as a core language library! #!/ffp/bin/env ruby require ‘open-uri’ require ‘rss’   CONFFILE=’/ffp/etc/mypodder.conf’ PODCASTDIR=’/mnt/HD_a2/podcasts’ […]

line numbers in shell

AKA ‘Today’s exciting shell command I learned’ nl e.g. $ echo -e "hello\ncruel\nworld" | nl 1 hello 2 cruel 3 world

ack – best thing since sliced bread

Someone at work recently pointed out ack. It’s a powerful replacement for find and grep. My favorite features: it ignores CVS/.svn directories; can easily specify file types with a flag (and of course define your own types); and it has colour highlighting on the output. On Ubuntu it is called ‘ack-grep’ instead of just ‘ack’: […]

cut with multiple spaces

Today’s little command line lesson. Unix cut command takes a parameter which tells it the delimiter character to use. Often this is a space. However it only ever matches a single character, so when you have a line with extra spacing to make some columns line up, this doesn’t work right. Instead of just using […]

log file processing

I seem to have been doing lots of this kind of thing recently. grep "FOUND query" bak0*b_hac-server.log | awk ‘{print $8}’ | awk ‘BEGIN { FS = "|" }; { print $6 }’ | sort | uniq -c Remember, usually you want to sort before uniq.