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:21] 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 29: Line 29:
 </code> </code>
  
-  Note that the total field multiples $2 with $3.+<WRAP info> 
 +**NOTE:**  The total multiples fields $2 with $3. 
 +</WRAP>
  
 +----
  
 AWK supports the full range of arithmetic operators including: AWK supports the full range of arithmetic operators including:
Line 52: 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 68: 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 91: 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.1609946464.txt.gz · Last modified: 2021/01/06 15:21 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki