Archive for 'bash' Category
Bash using ruby for min and max
16 November 2009alias min=’ruby -e “ARGF.select{|e| e =~ /^[+-]?d+[.]?d*/ }.map{|e| e.to_f }.min”‘
alias max=’ruby -e “ARGF.select{|e| e =~ /^[+-]?d+[.]?d*/ }.map{|e| e.to_f }.max”‘
Then you can simply do
[user@host]# echo “1″ >> numbers.txt
[user@host]# echo “5″ >> numbers.txt
[user@host]# cat numbers.txt | min
1
Google from the command line
6 June 2008#!/bin/bash
query=”$@”
if [ -z “$query” ]; then
echo “Usage: google < search term >”
echo “You must specify a search query”
exit -1
fi
query=`echo $query | sed -e s/’ ‘/%20/g`
w3m -dump -no-cookie -cols 200 http://www.google.com/search?q=${query} | grep Cached | cut -f 1 -d’ ‘
Bash variables
6 June 2008From the bash documentation… here for my special reference guide.
3.4.2 Special Parameters
The shell treats several parameters specially. These parameters may only be referenced; assignment to them is not allowed.
* Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, it expands to a single word with the […]
Vim indent script
14 November 2007I’ve been using vi a lot lately and was bummed to have forgotten a very nice piece of .vimrc magic I used to have to autoindent an entire file at once. The way it works is you stick the following in your ~/.vimrc and then in any file you can just press — and it […]