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:11] – [Basic BEGIN Statement] 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 ITEM QUANTITY PRICE | NUMBER ITEM QUANTITY PRICE | ||
1 10 Peter Terence | 1 10 Peter Terence | ||
- | 2 11 Virginia | + | 2 11 Virginia |
3 12 Felix Devon | 3 12 Felix Devon | ||
4 13 David Bruce | 4 13 David Bruce | ||
Line 53: | Line 55: | ||
6 48 Adam Winter | 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 61: | 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 89: | 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.1609945899.txt.gz · Last modified: 2021/01/06 15:11 by peter