Awk

From Attie's Wiki
(Difference between revisions)
Jump to: navigation, search
m (Created page with 'This page contains some example awk scripts. ==8-bit ADC battery voltage reading== Contents of <code>minicom.cap</code>: <source lang="text"> 160 159 159 159 158 158 158 158 157…')
 
m
Line 31: Line 31:
 
Command:
 
Command:
 
<source lang="bash">
 
<source lang="bash">
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)}'
+
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)}'
 
</source>
 
</source>
  

Revision as of 09:09, 28 October 2011

This page contains some example awk scripts.

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
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox