Extract to email from mail log file

awk -v FS="(<|>)" '{ print $2; }'   maillogfile

echo "[hello]" | awk -F"[\\\[\\\]]" '{ print $2; }'

>>> hello

# echo "P(G1,G3) foobar" | awk -F"[()]" '{print $2}'
G1,G3
# echo "P<G1,G3>" | awk -F"[<>]" '{print $2}'
G1,G3

the -F lets you chose what character(s) awk will use to split the line into fields. Here, I am giving it a character class ([]) consisting of opening and closing parentheses. So it will split the line on ( and on ). As a result, the 2nd field will be the contents of the parentheses.
 E.g, with the string G8 = P(G1,G3)foo
$1 will be G8 = P  and
$2 will be G1,G3 and 
$3 will be foo

Use awk to print values larger than certain number


Quick how to on using awk to filter results if a certain value (column) is larger than a set value.
For example, if you have a file (servers.txt) with lines in this format
a_datacenter, servers 20
 error, servers xyz
 b_datacenter, servers 21
 c_datacenter, servers 50
and you want to show only the lines that have server value larger than 20, you can do this in awk by running
grep datacenter servers.txt | awk '$3 > 20  {print ;}'

No comments:

Post a Comment