Monday, December 5, 2011

Using awk like grep

ubuntu1004@ubuntu1004:~$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              16G  3.5G   11G  25% /
none                  496M  260K  496M   1% /dev
none                  500M  256K  500M   1% /dev/shm
none                  500M   84K  500M   1% /var/run
none                  500M     0  500M   0% /var/lock
none                  500M     0  500M   0% /lib/init/rw
ubuntu1004@ubuntu1004:~$ df -h|grep sda1
/dev/sda1              16G  3.5G   11G  25% /
ubuntu1004@ubuntu1004:~$ df -h|grep sda1|awk '{print $5}'
25%
ubuntu1004@ubuntu1004:~$ df -h|awk '/sda1/'
/dev/sda1              16G  3.5G   11G  25% /
ubuntu1004@ubuntu1004:~$ df -h|awk '/sda1/ {print $5}'
25%
ubuntu1004@ubuntu1004:~$ df -h|awk '/sda1/ {print $4}'
11G
ubuntu1004@ubuntu1004:~$ df -h|awk '/sda1/ {print $4" "$5}'
11G 25%

No comments:

Post a Comment