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:37] – [Specifying Output Field Separator Delimiter] 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 ======
  
-===== Specifying Field Seperator Delimiter =====+Assuming a file exists, **test.txt**, with the following contents:
  
-To set an alternative field delimiter, issue the following command:+<file> 
 +10   Peter     Terence   Roux        45 
 +11   Virginia  Genevieve  Roux        45 
 +12   Felix     Devon     Roux         5 
 +13   David     Bruce     Stevenson   48 
 +14   Bob       James     Smith       16 
 +48   Adam      Winter    Ridley      23 
 +</file>
  
-<code bash+---- 
-awk '{FS=":"}{print $2,$4}' /sharewiz/awk/test.txt+ 
 +===== Specifying Input Field Separator Delimiter ===== 
 + 
 +To set an alternative field delimiter: 
 + 
 +<code awk
 +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>
  
-This is useful when a space is not being used as the delimiter in the input file.+<WRAP info> 
 +**NOTE:**  This is useful when a space is not being used as the delimiter in the input file. 
 + 
 +  * 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 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:
  
-<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 38: 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.1588635467.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki