0

I am trying to get the elapsedCpu time for a certain process using adb commands. I am using this command in order to get some info about the com.example.android process

adb shell cat /proc/1234/stat

(1234 is the PID of com.example.android)

The output result looks like this:

24334 (gdev.loadtester) S 490 490 0 0 -1 6545623 65464564 0 1 0 888 999 0 0 20 549351656579 549351656579 549351657438 0

I am only interested in the 14th group of numbers, that being 888. How do i trim this output in order to extract only this number, so that I have 888 as a result of the command. Each group of chars will always be separated by a space.

user3017513
  • 1,330
  • 1
  • 11
  • 8

2 Answers2

1

In awk:

$ awk '{print $14}' file

Explained some: By default awk uses spaces as input field separator FS (well..., see, for example, here). print $14 outputs the 14th FS separated field of each record.

Community
  • 1
  • 1
James Brown
  • 36,089
  • 7
  • 43
  • 59
0

I think I found the answer:

adb shell cat /proc/1234/stat "| cut -d ' ' -f 14"
user3017513
  • 1,330
  • 1
  • 11
  • 8