Awk
From Attie's Wiki
(Difference between revisions)
m |
m |
||
Line 1: | Line 1: | ||
This page contains some example awk scripts. | This page contains some example awk scripts. | ||
+ | |||
+ | ==Calculate size of all source in directory== | ||
+ | <source lang="bash"> | ||
+ | find . -type f -name '*.c' -exec ls -l {} \; | \ | ||
+ | tr -s ' ' | \ | ||
+ | cut -d ' ' -f 5 | \ | ||
+ | awk 'BEGIN{i=0} | ||
+ | {if (i) printf "+"; i = 1; printf $1} | ||
+ | END{printf "\n"}' | \ | ||
+ | bc | ||
+ | </source> | ||
==8-bit ADC battery voltage reading== | ==8-bit ADC battery voltage reading== |
Revision as of 21:56, 5 March 2012
This page contains some example awk scripts.
Calculate size of all source in directory
find . -type f -name '*.c' -exec ls -l {} \; | \ tr -s ' ' | \ cut -d ' ' -f 5 | \ awk 'BEGIN{i=0} {if (i) printf "+"; i = 1; printf $1} END{printf "\n"}' | \ bc
8-bit ADC battery voltage reading
Contents of minicom.cap
:
160 159 159 159 158 158 158 158 157 156 157 156 156 156 155 155 155 155 154 154 154 154 154
Command:
cat minicom.cap | sort -r | uniq -c | \ awk 'BEGIN{tot=0; printf "hh:mm\tvoltage\n"} {tot += $1; printf "%2d:%02d\t%.2fv\n", ($1/60), ($1%60), (((3.3 / 256) * $2) * 2)} END{printf "Total: %d:%02d\n", (tot/60), (tot%60)}'
Output:
hh:mm voltage 0:01 4.12v 0:03 4.10v 0:04 4.07v 0:02 4.05v 0:04 4.02v 0:04 4.00v 0:05 3.97v Total: 0:24