User Tools

Site Tools


awk:awk_fields

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
awk:awk_fields [2021/01/06 15:40] peterawk: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:
 </code> </code>
  
-which will display something like:+returns:
  
 <code> <code>
Line 33: Line 31:
 </code> </code>
  
-  * AWK has read each field in the file into the variables $1, $2, $3, etc.+<WRAP info> 
 +**NOTE:**  AWK has read each field in the file into the variables $1, $2, $3, etc. 
   * 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> +  * As AWK reads the input, the entire record is assigned to the variable $0. 
-**NOTE:* As AWK reads the input, the entire record is assigned to the variable $0.+
 </WRAP> </WRAP>
  
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:
 </code> </code>
  
-which will display something like:+returns:
  
 <code> <code>
Line 71: Line 71:
 </code> </code>
  
-result:+returns:
  
 <code> <code>
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:
 </code> </code>
  
-which will display something like:+returns:
  
 <code> <code>
Line 112: Line 112:
 </code> </code>
  
-The semicolon (;) indicates to write some data to a different line.+<WRAP info> 
 +**NOTE:**  The semicolon (;) indicates to write some data to a different line. 
 +</WRAP> 
  
 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

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki