Shell - awk command (grep and sed) - Output filtering

> Procedural Languages > Bash Shell and (Unix|Linux) Utilities (XCU)

1 - About

The awk command combines the functions of:

AWK is a (tool|language) for event-based data processing.

Advertising

3 - Example

3.1 - ls

Linux - ls (List directory content) with only acl information.

ls -l | grep pls.txt |  awk '{print $1, $2, $3, $4}'
-rw-rw---- 1 oracle oinstall

3.2 - To get the cached memory

With the free command:

[[email protected] ~]$ free | grep Mem | awk '{print $7}'
137329856
[[email protected] ~]$ free
             total       used       free     shared    buffers     cached
Mem:    1058964444 1011201796   47762648          0    1272644  137329872
-/+ buffers/cache:  872599280  186365164
Swap:    101023736       4392  101019344

3.3 - Escape

Example on how to escape the :

awk '{print $1"\:"$2}'
Advertising

4 - Documentation / Reference