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?
$
in sed command.ms$
toms.*$
, and that solved the problem. Thanks!