AWK is a programming language designed for processing text-based data, either in files or data streams. Calculating incoming stream is not a big deal with awk. You can add two numbers as follows:
# add 2 + 5Create a text file called numbers as follows /tmp/numbers:
echo |awk '{ print 2+3 }'
# add incoming 10 + 10
echo 10 | awk '{ print $1 + 10}'
10To add numbers, enter:
20
30
awk '{total += $1}END{ print total}' /tmp/numbersSample outputs:
60Use the ps command output (stream) to calculate total size of php-cgi process using awk, enter:
Sample outputs:
ps -aylC php-cgi | grep php-cgi | awk '{total += $8}END{size= total / 1024; printf "php-cgi total size %.2f MB\n", size}'
php-cgi total size 2004.21 MB
No comments:
Post a Comment