User Tools

Site Tools


awk:awk_output

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_output [2020/05/04 23:29] peterawk:awk_output [2022/06/13 09:47] (current) peter
Line 1: Line 1:
 ====== AWK - AWK Output ====== ====== AWK - AWK Output ======
  
-Assuming a file exists with the following contents:+Assuming a file, **test.txt** exists 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 16: Line 16:
 ===== Display Tidy Output ===== ===== Display Tidy Output =====
  
-Multiple commands can be passed together.  For instance issue the following command:+Multiple commands can be passed together.
  
-<code bash+<code awk
-awk '/45/ {print $2,$3,$4} {print $1": "$5"\n"}' /sharewiz/awk/test.txt+awk '/45/ {print $2,$3,$4} {print $1": "$5"\n"}' test.txt
 </code> </code>
  
-which will display something like:+returns:
  
 <code> <code>
Line 28: Line 28:
 10: 45 10: 45
  
-Virginia Genevive Roux+Virginia Genevieve Roux
 11: 45 11: 45
  
Line 40: Line 40:
 </code> </code>
  
-  * This inserts a colon and a space and comma between $1 and $5. +<WRAP info> 
-  It also inserts new line after each two-line display.+**NOTE:**  This inserts a colon and a space and comma between $1 and $5. 
 + 
 +It also inserts new line after each two-line display. 
 + 
 +</WRAP> 
 + 
 +----
  
 Certain escape sequences are supported, including: Certain escape sequences are supported, including:
Line 59: Line 65:
 ===== Adding Text ===== ===== Adding Text =====
  
-Additional text can be added to lines. For instance issue the following command:+Additional text can be added to lines.
  
-<code bash+<code awk
-awk '/45/ {print "NAME: "$2,$3,$4 "\tAGE: "$5}' /sharewiz/awk/test.txt+awk '/45/ {print "NAME: "$2,$3,$4 "\tAGE: "$5}' test.txt
 </code> </code>
  
-which will display something like:+returns:
  
 <code> <code>
 NAME: Peter Terence Roux AGE: 45 NAME: Peter Terence Roux AGE: 45
-NAME: Virginia Genevive Roux AGE: 45+NAME: Virginia Genevieve Roux AGE: 45
 </code> </code>
  
-The values between double quotes can be anything.+<WRAP info> 
 +**NOTE:**  The values between double quotes can be anything. 
 +</WRAP> 
  
 ---- ----
Line 78: Line 87:
 ===== Advanced Text Output ===== ===== Advanced Text Output =====
  
-For more complex manipulation of text issue the following command: +<code awk
- +awk '/45/ {printf ("%s %d %x %s\n", $2,$5,$5,"x")}' test.txt
-<code bash+
-awk '/45/ {printf ("%s %d %x %s\n", $2,$5,$5,"x")}' /sharewiz/awk/test.txt+
 </code> </code>
  
-which will display something like:+returns:
  
 <code> <code>
Line 91: Line 98:
 </code> </code>
  
-The **printf** command can be used to handle more complex output requirements.+<WRAP info> 
 +**NOTE:**  The **printf** command can be used to handle more complex output requirements.
  
 This is the list of specifications supported by the printf command: This is the list of specifications supported by the printf command:
Line 105: Line 113:
 |%x|Prints an unsigned hexadecimal number.| |%x|Prints an unsigned hexadecimal number.|
 |%%|Prints a percent sign; no conversion is performed.| |%%|Prints a percent sign; no conversion is performed.|
 +
 +
 +</WRAP>
  
 ---- ----
  
awk/awk_output.1588634995.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki