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
Next revision
Previous revision
awk:awk_fields [2020/07/15 09:30] – external edit 127.0.0.1awk:awk_fields [2022/06/13 09:37] (current) peter
Line 5: Line 5:
 <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 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>
 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 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>
 Peter Terence Roux Peter Terence Roux
 10 45 10 45
-Virginia Genevive Roux+Virginia Genevieve Roux
 11 45 11 45
 Felix Devon Roux Felix Devon Roux
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.1594805433.txt.gz · Last modified: 2020/07/15 09:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki