3

I have a shell command to get the UI drawing time for an Android app (which is not really relevant to this question) in milliseconds. At any rate, the output looks like

I/ActivityManager( 1843): Fully drawn com.amazon.android.calypso/com.amazon.android.tv.tenfoot.ui.activities.ContentBrowseActivity: [time]

Where [time] is of the format +###ms or +#s###ms (again, not relevant here).

The command is as follows:

adb logcat -d | grep 'Fully drawn' | sed -e 's/^.*: +\(.*\)ms$/\1/' -e 's/s//'

It works as expected when I use echo to directly display the output:

$ echo 'I/ActivityManager( 1843): Fully drawn com.amazon.android.calypso/com.amazon.android.tv.tenfoot.ui.activities.ContentBrowseActivity: +233ms' | sed -e 's/^.*: +\(.*\)ms$/\1/' -e 's/s//'
> 233

$ echo 'I/ActivityManager( 1843): Fully drawn com.amazon.android.calypso/com.amazon.android.tv.tenfoot.ui.activities.ContentBrowseActivity: +1s233ms' | sed -e 's/^.*: +\(.*\)ms$/\1/' -e 's/s//'
> 1233

However, when I use it on other commands that should display an output of the same format, sed matches the whole line rather than just the rendering time:

$ adb logcat -d | grep 'Fully drawn' | sed -e 's/^.*: +\(.*\)ms$/\1/' -e 's/s//'
> I/ActivityManager( 1843): Fully drawn com.amazon.android.calypo/com.amazon.android.tv.tenfoot.ui.activities.ContentBrowseActivity: +233ms

The same happens when I put the output into a variable first.

$ out="$(adb logcat -d | grep 'Fully drawn')"                                           
$ echo $out | sed -e 's/^.*: +\(.*\)ms$/\1/' -e 's/s//'
> I/ActivityManager( 1843): Fully drawn com.amazon.android.calypo/com.amazon.android.tv.tenfoot.ui.activities.ContentBrowseActivity: +233ms

Tried dumping the output into a text file, no dice:

adb logcat -d | grep 'Fully drawn' > temp.txt
cat temp.txt | sed -e 's/^.*: +\(.*\)ms$/\1/' -e 's/s//'
> I/ActivityManager( 1843): Fully drawn com.amazon.android.calypo/com.amazon.android.tv.tenfoot.ui.activities.ContentBrowseActivity: +233ms

Anyone know why this is the case?

3
  • 1
    adb may produce dos-like CR/LF at the end of lines. Try to skip the trailing $ in sed command. Nov 22, 2016 at 4:56
  • Yeah, I think that's the cause. I changed the ms$ to ms.*$, and that solved the problem. Thanks!
    – Danny
    Nov 22, 2016 at 5:06
  • @IporSircer Perhaps do a write up as answer so the OP can close thread?
    – ejbytes
    Nov 22, 2016 at 6:17

1 Answer 1

2

adb produces dos-like CR/LF at the end of lines. Try to skip the trailing $ in sed command.

You must log in to answer this question.

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