AWK Formatting Output Flashcards
Common escape sequences for echo -e or printf:
\b
Backspace
Common escape sequences for echo -e or printf:
\f
Form feed
Common escape sequences for echo -e or printf:
\n
Newline (line feed)
Common escape sequences for echo -e or printf:
\r
carriage return
Common escape sequences for echo -e or printf:
\t
horizontal tab
Common escape sequences for echo -e or printf:
\v
vertical tab
awk ‘BEGIN{printf “|%10s|\n”, “hello”}’
Right align
| hello|
awk ‘BEGIN{printf “|%-10s|\n”, “hello”}’
Left align
|hello |
Common AWK specifiers:
c
ASCII Character
Common AWK specifiers:
d
Decimal integer
Common AWK specifiers:
e, E, F
FLoating-point format
Common AWK specifiers:
o
Unsigned octal value
Common AWK specifiers:
s
String
Common AWK specifiers:
%
Literal %
Break down how this ss output is parsed with AWK:
ss -lunt | awk ‘NR>1{i=split($5,a,”:”);print a[i]}’
ss -lunt
Lists TCP ports that are listening
and Lists UDP ports that are open
NR>1
skip the first line
i=split($5,a,”:”)
split our input in field 5 (delimiter is colon)
print a[i]
print the last field from each split operation