1

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 Answers1

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.

faadi
  • 169