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:37] – [Specifying Output Field Separator Delimiter] 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 ====== | ||
- | ===== Specifying Field Seperator Delimiter ===== | + | Assuming a file exists, **test.txt**, |
- | To set an alternative field delimiter, issue the following command: | + | < |
+ | 10 | ||
+ | 11 | ||
+ | 12 | ||
+ | 13 | ||
+ | 14 | ||
+ | 48 | ||
+ | </ | ||
- | < | + | ---- |
- | awk ' | + | |
+ | ===== Specifying Input Field Separator Delimiter ===== | ||
+ | |||
+ | To set an alternative field delimiter: | ||
+ | |||
+ | < | ||
+ | awk ' | ||
</ | </ | ||
or | or | ||
- | < | + | < |
- | awk -F: ' | + | awk -F: ' |
</ | </ | ||
- | This is useful when a space is not being used as the delimiter in the input file. | + | <WRAP info> |
+ | **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 21: | 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 38: | Line 58: | ||
</ | </ | ||
- | The **OFS** variable is used to specify the output delimiter. | + | <WRAP info> |
+ | **NOTE: | ||
+ | </ | ||
awk/awk_field_separator_delimiters.1588635467.txt.gz · Last modified: 2020/07/15 09:30 (external edit)