I'm using macOS Sierra and I would like to log a process with the top command and store all the information in a file. I'm using the following command:

top | grep --line-buffered "PROCESS" > test.txt

This perfectly works, but I would like to select only certain columns as the reseults:

  1. PID
  2. Memory Usage
  3. CPU Usage
  4. Network Usage
  5. Disk Usage

Is there a way to filter the top result and select only the columns of my interest?

1 Answer 1


You can run this command in a loop.

top -l 1 | grep "PROCESS" | awk '{print $1,$2}' >> test.txt

Use awk to select the respective columns you want to include in your logs. For example, $1 is the first column, $2 is the second and so on.

  • invalid option or syntax: -b Sep 29, 2016 at 17:04
  • @user1849976 Try now. I've edited the answer
    – faadi
    Sep 29, 2016 at 17:12
  • Ok, now the command works, but how to run it once a second? Sep 29, 2016 at 17:21
  • Try the watch command or sleep in bash. See: unix.stackexchange.com/questions/10646/…
    – faadi
    Sep 29, 2016 at 17:26
  • 1
    can use awk '/PROCESS/{print $1,$2}' instead of grep + awk combo :)
    – Sundeep
    Sep 30, 2016 at 4:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .