awk:awk_output
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
awk:awk_output [2020/05/04 23:32] – [Adding Text] peter | awk: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** |
< | < | ||
10 | 10 | ||
- | 11 | + | 11 |
12 | 12 | ||
13 | 13 | ||
Line 16: | Line 16: | ||
===== 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 28: | Line 28: | ||
10: 45 | 10: 45 | ||
- | Virginia | + | Virginia |
11: 45 | 11: 45 | ||
Line 40: | 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 59: | 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 |
</ | </ | ||
Line 81: | 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 94: | 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 108: | 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.1588635137.txt.gz · Last modified: 2020/07/15 09:30 (external edit)