awk:awk_field_separator_delimiters
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
awk:awk_field_separator_delimiters [2020/05/04 23:39] – peter | awk:awk_field_separator_delimiters [2022/06/13 09:41] (current) – peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== AWK - AWK Field Separator Delimiters ====== | ====== AWK - AWK Field Separator Delimiters ====== | ||
- | Assuming a file exists with the following contents: | + | Assuming a file exists, **test.txt**, |
< | < | ||
10 | 10 | ||
- | 11 | + | 11 |
12 | 12 | ||
13 | 13 | ||
Line 14: | Line 14: | ||
---- | ---- | ||
- | ===== Specifying Field Separator Delimiter ===== | + | ===== Specifying |
- | To set an alternative field delimiter, issue the following command: | + | To set an alternative field delimiter: |
- | < | + | < |
- | awk ' | + | awk ' |
</ | </ | ||
or | or | ||
- | < | + | < |
- | awk -F: ' | + | awk -F: ' |
</ | </ | ||
<WRAP info> | <WRAP info> | ||
**NOTE: | **NOTE: | ||
- | </ | ||
+ | * AWK **FS** is any single character or regular expression which you want to use as a input field separator. | ||
+ | * AWK **FS** can be changed any number of times, it retains its values until it is explicitly changed. | ||
+ | * If you want to change the field separator, its better to change before you read the line; so the change affects the line that is read. | ||
+ | |||
+ | </ | ||
---- | ---- | ||
Line 37: | Line 41: | ||
===== Specifying Output Field Separator Delimiter ===== | ===== Specifying Output Field Separator Delimiter ===== | ||
- | To set an alternative field delimiter for the output, issue the following command: | + | To set an alternative field delimiter for the output: |
- | < | + | < |
- | awk ' | + | awk ' |
</ | </ | ||
- | which will display something like: | + | returns: |
< | < | ||
Line 54: | Line 58: | ||
</ | </ | ||
- | The **OFS** variable is used to specify the output delimiter. | + | <WRAP info> |
+ | **NOTE: | ||
+ | </ | ||
awk/awk_field_separator_delimiters.1588635559.txt.gz · Last modified: 2020/07/15 09:30 (external edit)