User Tools

Site Tools


awk:awk_field_separator_delimiters

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
awk:awk_field_separator_delimiters [2020/05/04 23:39] peterawk: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**, with the following contents:
  
 <file> <file>
 10   Peter     Terence   Roux        45 10   Peter     Terence   Roux        45
-11   Virginia  Genevive  Roux        45+11   Virginia  Genevieve  Roux        45
 12   Felix     Devon     Roux         5 12   Felix     Devon     Roux         5
 13   David     Bruce     Stevenson   48 13   David     Bruce     Stevenson   48
Line 14: Line 14:
 ---- ----
  
-===== Specifying Field Separator Delimiter =====+===== Specifying Input Field Separator Delimiter =====
  
-To set an alternative field delimiter, issue the following command:+To set an alternative field delimiter:
  
-<code bash+<code awk
-awk '{FS=":"}{print $2,$4}' /sharewiz/awk/test.txt+awk '{FS=":"}{print $2,$4}' test.txt
 </code> </code>
  
 or or
  
-<code bash+<code awk
-awk -F: '{print $2,$4}' /sharewiz/awk/test.txt+awk -F: '{print $2,$4}' test.txt
 </code> </code>
  
 <WRAP info> <WRAP info>
 **NOTE:**  This is useful when a space is not being used as the delimiter in the input file. **NOTE:**  This is useful when a space is not being used as the delimiter in the input file.
-</WRAP> 
  
 +  * 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.
 +
 +</WRAP>
  
 ---- ----
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:
  
-<code bash+<code awk
-awk '{OFS="-"}{print $2,$4}' /sharewiz/awk/test.txt+awk '{OFS="-"}{print $2,$4}' test.txt
 </code> </code>
  
-which will display something like:+returns:
  
 <code> <code>
Line 54: Line 58:
 </code> </code>
  
-The **OFS** variable is used to specify the output delimiter.+<WRAP info> 
 +**NOTE:**  The **OFS** variable is used to specify the output delimiter. 
 +</WRAP> 
  
awk/awk_field_separator_delimiters.1588635559.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki