awk:awk_output
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
awk:awk_output [2020/05/04 23:29] – created peter | awk:awk_output [2022/06/13 09:47] (current) – peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== AWK - AWK Output ====== | ====== AWK - AWK Output ====== | ||
+ | |||
+ | Assuming a file, **test.txt** exists with the following contents: | ||
+ | |||
+ | < | ||
+ | 10 | ||
+ | 11 | ||
+ | 12 | ||
+ | 13 | ||
+ | 14 | ||
+ | 48 | ||
+ | </ | ||
+ | |||
+ | ---- | ||
===== Display Tidy Output ===== | ===== Display Tidy Output ===== | ||
- | Multiple commands can be passed together. | + | Multiple commands can be passed together. |
- | < | + | < |
- | awk '/45/ {print $2,$3,$4} {print $1": " | + | awk '/45/ {print $2,$3,$4} {print $1": " |
</ | </ | ||
- | which will display something like: | + | returns: |
< | < | ||
Line 15: | Line 28: | ||
10: 45 | 10: 45 | ||
- | Virginia | + | Virginia |
11: 45 | 11: 45 | ||
Line 27: | Line 40: | ||
</ | </ | ||
- | | + | <WRAP info> |
- | | + | **NOTE: |
+ | |||
+ | It also inserts new line after each two-line display. | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
Certain escape sequences are supported, including: | Certain escape sequences are supported, including: | ||
Line 46: | Line 65: | ||
===== Adding Text ===== | ===== Adding Text ===== | ||
- | Additional text can be added to lines. | + | Additional text can be added to lines. |
- | < | + | < |
- | awk '/45/ {print "NAME: " | + | awk '/45/ {print "NAME: " |
</ | </ | ||
- | which will display something like: | + | returns: |
< | < | ||
NAME: Peter Terence Roux AGE: 45 | NAME: Peter Terence Roux AGE: 45 | ||
- | NAME: Virginia | + | NAME: Virginia |
</ | </ | ||
- | The values between double quotes can be anything. | + | <WRAP info> |
+ | **NOTE: | ||
+ | </ | ||
---- | ---- | ||
Line 65: | Line 87: | ||
===== Advanced Text Output ===== | ===== Advanced Text Output ===== | ||
- | For more complex manipulation of text issue the following command: | + | < |
- | + | awk '/45/ {printf ("%s %d %x %s\n", $2, | |
- | < | + | |
- | awk '/45/ {printf ("%s %d %x %s\n", $2, | + | |
</ | </ | ||
- | which will display something like: | + | returns: |
< | < | ||
Line 78: | Line 98: | ||
</ | </ | ||
- | The **printf** command can be used to handle more complex output requirements. | + | <WRAP info> |
+ | **NOTE: | ||
This is the list of specifications supported by the printf command: | This is the list of specifications supported by the printf command: | ||
Line 92: | 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.| | ||
+ | |||
+ | |||
+ | </ | ||
---- | ---- | ||
awk/awk_output.1588634974.txt.gz · Last modified: 2020/07/15 09:30 (external edit)