I never found the need to study those common unix utilities like
sed,
awk,
xargs. Even my knowledge of grep didn't go further than
blah | grep foo. Until yesterday, when I needed to accomplish a task that just happened to involve all of these utilities:
grep ppp /proc/net/dev | sed "s/:/ /" | awk '($2+$10>1000000000){print $1}' | xargs --max-args=1 --no-run-if-empty ppp-off
First,
grep filters all lines from
/proc/net/dev that contain
ppp.
Then,
sed changes the colon into a space using the regex
s/:/ /.
Next,
awk parses the values of the 2nd and 10th column [bytes sent and received] and if the sum exceeds 1GB it prints the value in the first column [the interface].
Finally,
xargs invokes ppp-off for every interface returned.
Why I needed this is left as an exercise to the reader.