I need to print the whole output sorted based on 'Resident Set Size' value.
Process: wccpd
Memory (bytes)
Total Virtual Size 29.5
Resident Set Size 4.0
Process: writeback
Memory (bytes)
Total Virtual Size 0
Resident Set Size 0
Process: zxfrd
Memory (bytes)
Total Virtual Size 71.3
Resident Set Size 3.9
perlis pretty good at this sort of thing:The idea is pretty simple. Setting
$/(aka$INPUT_RECORD_SEPARATORor$RS) to the empty string putsperlin "paragraph mode" where records are separated by blank lines. We then read the file one record at a time and parse each record to match "Resident Set Size" and find the value on which you wish to sort. We then push an array reference consisting of the value in [0] and the whole record in [1]. Then you use the<=>operator to compare the records in the sort function.If you have your input in the file
inputand want to execute something like this directly, you can do:This is precisely the same as the above script, where the
-nperforms thewhile(<>)loop and-00enables paragraph mode. The oddly mismatchted} {are aperlidiom for use with-n. The-nflag basically puts awhile(<>){ }loop around the entire script, and we are closing that loop with the first}and matching its closing brace with the (seemingly unmatched){.