awk:awk_fields
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
awk:awk_fields [2021/01/06 15:40] – peter | awk:awk_fields [2022/06/13 09:37] (current) – peter | ||
---|---|---|---|
Line 15: | Line 15: | ||
===== Understanding Fields ===== | ===== Understanding Fields ===== | ||
- | |||
- | Issue the following command: | ||
<code awk> | <code awk> | ||
Line 22: | Line 20: | ||
</ | </ | ||
- | which will display something like: | + | returns: |
< | < | ||
Line 33: | Line 31: | ||
</ | </ | ||
- | | + | <WRAP info> |
+ | **NOTE: | ||
* Each field is split by a field separator, which by default is a space or comma. | * Each field is split by a field separator, which by default is a space or comma. | ||
* As can be seen, it does not matter how many spaces separate each field in the input file. | * As can be seen, it does not matter how many spaces separate each field in the input file. | ||
- | <WRAP info> | + | |
- | **NOTE:** As AWK reads the input, the entire record is assigned to the variable $0. | + | |
</ | </ | ||
Line 45: | Line 45: | ||
===== Display Only Certain Fields ===== | ===== Display Only Certain Fields ===== | ||
- | To only print the name and surname, i.e. fields $2 and $4, issue the following command: | + | To only print the name and surname, i.e. fields $2 and $4: |
<code awk> | <code awk> | ||
Line 51: | Line 51: | ||
</ | </ | ||
- | which will display something like: | + | returns: |
< | < | ||
Line 71: | Line 71: | ||
</ | </ | ||
- | result: | + | returns: |
< | < | ||
Line 89: | Line 89: | ||
===== Display Multi-line Output ===== | ===== Display Multi-line Output ===== | ||
- | To output onto multiple lines, issue the following command: | + | To output onto multiple lines: |
<code awk> | <code awk> | ||
Line 95: | Line 95: | ||
</ | </ | ||
- | which will display something like: | + | returns: |
< | < | ||
Line 112: | Line 112: | ||
</ | </ | ||
- | The semicolon (;) indicates to write some data to a different line. | + | <WRAP info> |
+ | **NOTE: | ||
+ | </ | ||
This could also be written as the following, which will produce the same results: | This could also be written as the following, which will produce the same results: |
awk/awk_fields.1609947600.txt.gz · Last modified: 2021/01/06 15:40 by peter