awk:begin_and_end
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
awk:begin_and_end [2021/01/06 15:10] – peter | awk:begin_and_end [2022/06/13 09:40] (current) – peter | ||
---|---|---|---|
Line 13: | Line 13: | ||
< | < | ||
10 | 10 | ||
- | 11 | + | 11 |
12 | 12 | ||
13 | 13 | ||
Line 30: | Line 30: | ||
</ | </ | ||
- | which will display something like: | + | returns: |
< | < | ||
NUMBER | NUMBER | ||
</ | </ | ||
+ | |||
+ | ---- | ||
This would be more useful when run as: | This would be more useful when run as: | ||
Line 42: | Line 44: | ||
</ | </ | ||
- | which will display something like: | + | returns: |
< | < | ||
- | NUMBER | + | NUMBER ITEM QUANTITY PRICE |
- | 1 pens 10 1.99 | + | 1 10 Peter Terence |
- | 2 pencils 20 3.99 | + | 2 11 Virginia Genevieve |
- | 3 staplers | + | 3 12 Felix Devon |
- | 4 rulers 12 2.50 | + | 4 13 David Bruce |
+ | 5 14 Bob James | ||
+ | 6 48 Adam Winter | ||
</ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
* The **BEGIN** has allowed the header to be added to the output. | * The **BEGIN** has allowed the header to be added to the output. | ||
* The **NR** variable used in the 2nd print numbers each line. It is a built-in variable of AWK. | * The **NR** variable used in the 2nd print numbers each line. It is a built-in variable of AWK. | ||
+ | |||
+ | </ | ||
---- | ---- | ||
Line 59: | Line 68: | ||
===== Basic END Statement ===== | ===== Basic END Statement ===== | ||
+ | |||
+ | Assuming a file, **test2.txt**, | ||
+ | |||
+ | < | ||
+ | pens 10 1.99 | ||
+ | pencils | ||
+ | staplers | ||
+ | rulers | ||
+ | </ | ||
Issue the following command: | Issue the following command: | ||
<code awk> | <code awk> | ||
- | awk ' | + | awk ' |
</ | </ | ||
- | which will display something like: | + | returns: |
< | < | ||
Total Value of Inventory: 174.65 | Total Value of Inventory: 174.65 | ||
</ | </ | ||
+ | |||
+ | ---- | ||
This would be more useful when run as: | This would be more useful when run as: | ||
<code awk> | <code awk> | ||
- | awk ' | + | awk ' |
</ | </ | ||
- | which will display something like: | + | returns: |
< | < | ||
Line 87: | Line 107: | ||
Total Value of Inventory: 174.65 | Total Value of Inventory: 174.65 | ||
</ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
* The **END** has allowed a total line to be added to the output. | * The **END** has allowed a total line to be added to the output. | ||
* It is only run at the end. | * It is only run at the end. | ||
+ | |||
+ | </ | ||
---- | ---- | ||
awk/begin_and_end.1609945827.txt.gz · Last modified: 2021/01/06 15:10 by peter