Skip to content
Advertisement

how to grep lines according to 6th field contents

I would like to know how to filter lines according to the mem usage: I would like to be able to find only the PIDs that (RES mem usage) exceed 5GB

Explicitly, I have the following lines

20697 user    20   0  357m  24m  19m S 19.0  0.1 887:15.00 pulseaudio
13017 user    20   0 8381m 3.7g  35m S 127.7  7.9 803:11.96 MATLAB
12654 user    20   0 11.2g 6.1g  10m S 104.8 13.0 784:41.07 MATLAB
3088 user    20   0 17.4g  12g  11m S 101.0 26.3   2043:48 MATLAB
12548 user    20   0 8797m 3.5g  13m S 101.0  7.4 802:21.00 MATLAB
12785 user    20   0 8543m 3.6g  35m S 101.0  7.6 804:36.81 MATLAB
12909 user    20   0 12.1g 5.5g  28m S 99.1 11.8 796:01.45 MATLAB
13154 user    20   0 10.1g 5.6g  10m S 99.1 11.8 797:07.14 MATLAB

and I’d like to grep only the lines where the 6th field is larger than 5 GB

EDIT: Note that sorting is not important. Just selecting the lines that exceed the threshold is important.

Thanks!

Advertisement

Answer

$ awk '$6~/g/ && ($6+0)>5' file
12654 user    20   0 11.2g 6.1g  10m S 104.8 13.0 784:41.07 MATLAB
3088 user    20   0 17.4g  12g  11m S 101.0 26.3   2043:48 MATLAB
12909 user    20   0 12.1g 5.5g  28m S 99.1 11.8 796:01.45 MATLAB
13154 user    20   0 10.1g 5.6g  10m S 99.1 11.8 797:07.14 MATLAB
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement