Search code examples
regexlinuxsunos

regex for swap info in SunOs


swap command : /usr/sbin/swap -s

I even tried something like awk '/total/ {print $2}' /usr/sbin/swap -s but gives me error

swap output :

total: 12417784k bytes allocated + 2705800k reserved = 15123584k used, 45459976k available

I need to get used an available values i.e., 15123584k and 45459976k respectively.


Solution

  • Use a pipe to pass the output of swap to awk

    /usr/sbin/swap -s | awk '/total/ {print $2}' 
    

    To get the value of 15123584k and 45459976k, we print out column 9 and column 11 using

    /usr/sbin/swap -s | awk '/total/ {print $9" "$11}'