September 5, 2012 – 1:17 pm
A little Perl snippet for sampling a log file (or whatever): grep something myfile | perl -n -e ‘print if $. % 12 == 1;’
October 19, 2010 – 11:29 am
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 […]
April 26, 2010 – 12:29 pm
ORIGIFS=$IFS; IFS=`echo -en "\n\b"`; for line in $(cat my_list_file); do echo $line; done; IFS=$ORIGIFS
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 […]
November 24, 2009 – 8:57 am
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 […]
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’ […]
January 20, 2009 – 11:18 am
AKA ‘Today’s exciting shell command I learned’ nl e.g. $ echo -e "hello\ncruel\nworld" | nl 1 hello 2 cruel 3 world
January 16, 2009 – 1:04 pm
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’: […]
December 16, 2008 – 8:39 am
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 […]
September 23, 2008 – 8:29 am
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.