Issue
I was doing some adb shell
stuff on windows and stuck at a point. Here's what I was doing..
I was printing all installed apps on my phone and getting their exact path.
zeroltetmo:/ # pm list packages -f
package:/system/app/FilterProvider/FilterProvider.apk=com.samsung.android.provider.filterprovider
package:/system/priv-app/CtsShimPrivPrebuilt/CtsShimPrivPrebuilt.apk=com.android.cts.priv.ctsshim
package:/system/app/YouTube/Youtube.apk=com.google.android.youtube
package:/system/app/vsimservice/vsimservice.apk=com.sec.vsimservice
package:/system/priv-app/WallpaperCropper/WallpaperCropper.apk=com.android.wallpapercropper
package:/system/framework/framework-res.apk=android
package:/system/framework/samsung-framework-res/samsung-framework-res.apk=com.samsung.android.framework.res
package:/data/app/com.whatsapp-1/base.apk=com.whatsapp
package:/data/app/ru.meefik.busybox-2/base.apk=ru.meefik.busybox
package:/data/app/com.google.android.play.games-1/base.apk=com.google.android.play.games
But,
I want this to print only system/app
directory but only upto folder
name instead of the full path. What i'm doing is piping this to grep
and using this pattern to get the result.
zeroltetmo:/ # pm list packages -f | grep -o "system/app.*\/"
system/app/FilterProvider/
system/app/RootPA/
system/app/YouTube/
system/app/ClipboardSaveService/
system/app/TetheringAutomation/
system/app/GoogleExtShared/
system/app/WfdBroker/
system/app/vsimservice/
system/app/USBSettings/
system/app/EasyOneHand3/
But the problem is this / at the end of folder name that I'm stuck with.
Solution
You can filter the trailing slashes out with sed
like that:
pm list packages -f | grep -o "system/app.*/" | sed 's,/$,,'
Explanation of the sed
command:
s
stands for substitution
,
delimits command name from its arguments - it's easier to use something different /
when we want to replace /
/$
- string to be replaced. In this case it means slash at the end of the line
The string to replace /$
with is empty because we want to remove it.
Answered By - Arkadiusz Drabczyk
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.