When I run the following command on shell adb devices
. It shows me a bunch of devices like
List of devices attached
10.16.95.35:5555 device
10.16.95.36:5555 offline
10.16.95.37:5555 device
10.16.95.38:5555 device
10.16.95.39:5555 device
10.16.95.40:5555 device
10.16.95.41:5555 offline
10.16.95.42:5555 device
10.16.95.43:5555 device
10.16.95.44:5555 device
I am trying to get only offline deviceIps as a list. So the output in this case I desire is 10.16.95.36,10.16.95.41
I was able to get just offline listed as through adb devices | grep offline
10.16.95.36:5555 offline
10.16.95.41:5555 offline
but i do not know how to process it further to get 10.16.95.36,10.16.95.41
.
CodePudding user response:
You can use cut
with colon as -d
delimiter to get the first -f
field.
Then use paste
with -s
and -d
CodePudding user response:
Elaborating on jordanm's comment,
$: adb devices|awk -F: 'BEGIN{c=""} /offline/{printf "%s%s",c,$1;c=","} END{printf "\n"}'
10.16.95.36,10.16.95.41
That should only get the lines you want, and format the way you asked.