Jul. 25, 2007
Today i’ve had the need to get the dimension of a files, in hexadecimal format.
Tired to do cut&paste from calc to shell, i decided to get this info only from shell.
In a few minutes, just the time to read manpages, here’s that i’ve done.
Start
$ ls -l images/*
totale 12952
-rw-r--r-- 1 massi massi 11117611 2007-07-25 11:28 ramdisk.gz
-rwxr-xr-x 1 massi massi 193336 2007-07-25 10:43 redboot.bin
-rwxr-xr-x 1 massi massi 1930140 2007-07-25 10:41 zImage
Too many data, we’ll get less with awk
$ ls -l images/* | awk '{print $5}'
11117611
193336
1930140
Now data are ok, but there’s an empty line: i need an help from tail
$ ls -l images/* | tail -n +2 | awk '{print $5}'
11117611
193336
1930140
Ok, empty line is disappeared. Now i’ve only to play with awk fields.
$ ls -l images/* | tail -n +2 | awk '{printf("%s: %s(dec) %x(hex)\n", $8 ,$5 , $5)}'
ramdisk.gz: 11117611(dec) a9a42b(hex)
redboot.bin: 193336(dec) 2f338(hex)
zImage: 1930140(dec) 1d739c(hex)
Done!
Stay tuned
Technorati Tags: awk, tail, bash




