Android – grep exact match

grep exact match… here is a solution to the problem.

grep exact match

I need grep to exactly match the result list from the ls command.

For example, if I ls a directory, the result is as follows:

system
.sys
sbin
proc
init.rc
init.mahimahi.rc
init.goldfish.rc
init

I want grep to see if there is a file named “init”. I need grep to return only one result. There is only one file named “init” in the list.


I’m doing this on an Android device. So here’s the full command :

adb shell ls / | grep -E "^init$"

I need to check if a directory exists on my android device and perform an action if it exists.

I

did this before using find in my batch script, but I need to do this using bash on linux and I want an exact match. If there is another directory or file that contains the string I’m searching for, this will avoid the problem.


I’ve tried the suggestions in the link below, but when I take “init” as a parameter, none of them return any results.

how-to-grep-the-exact-match

match-exact-word-using-grep

Related Problems and Solutions