October 2015
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  

Categories

October 2015
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  

Calculating percentages in bash

Calculating percentages in bash Dividing in bash will cause problems if the result is below zero. This is a problem when you’re trying to work out percentages. For example, if you simply want to divide 1 by 2 the result should be 0.5. However, bash returns the result 0:

user@computer:~> echo $(( 1 / 2 […]

IP address with ifconfig and sed

Well, my new favorite approach is to pipe ifconfig into a single sed command 🙂

ifconfig | sed -n -e ‘s/:127\.0\.0\.1 //g’ -e ‘s/ *inet addr:\([0-9.]\+\).*/\1/gp’

 

So, how does it work? Well, there are two filters (aka scripts, ie the parameters after the -e flags). The first one, s/:127\.0\.0\.1 //g’, simply strips out all […]