User Tools

Site Tools


awk:awk_math_operations

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
awk:awk_math_operations [2021/01/06 15:34] peterawk:awk_math_operations [2022/06/13 09:45] (current) – [Advanced Example Using a Variable] peter
Line 20: Line 20:
 </code> </code>
  
-which will display something like:+returns:
  
 <code> <code>
Line 55: Line 55:
  
 ===== Using a Variable ===== ===== Using a Variable =====
- 
-Issue the following command: 
  
 <code awk> <code awk>
-awk '{x=x+$2} {print x}' /sharewiz/awk/test2.txt+awk '{x=x+$2} {print x}' test2.txt
 </code> </code>
  
-which will display something like:+returns:
  
 <code> <code>
Line 71: Line 69:
 </code> </code>
  
-This assigns a variable named x.+<WRAP info> 
 +**NOTE:**  This assigns a variable named x.
  
 It has shown a running total and calculated an overall total of 47 items. It has shown a running total and calculated an overall total of 47 items.
 +
 +</WRAP>
  
 ---- ----
  
 ===== Advanced Example Using a Variable ===== ===== Advanced Example Using a Variable =====
- 
-Issue the following command: 
  
 <code awk> <code awk>
-awk '{x=x+($2*$3)}{print $1,"QTY: "$2,"PRICE: "$3,"TOTAL: "$2*$3,"BAL: "x}' /sharewiz/awk/test2.txt+awk '{x=x+($2*$3)}{print $1,"QTY: "$2,"PRICE: "$3,"TOTAL: "$2*$3,"BAL: "x}' test2.txt
 </code> </code>
  
-which will display something like:+returns:
  
 <code> <code>
Line 94: Line 93:
 </code> </code>
  
-This procedure gives a listing of each record while assigning a total value and keeping a running balance. +<WRAP info> 
 +**NOTE:**  This lists each record while assigning a total value and keeping a running balance. 
 +</WRAP>
  
 ---- ----
  
awk/awk_math_operations.1609947274.txt.gz · Last modified: 2021/01/06 15:34 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki