I'm getting list of devices IPs using this command:
# Get all devices from ADB server
wIP=$(adb devices | tail -n +2 | grep "device" | cut -f1 | cut -f1 -d\ );
Result $wIP is:
192.168.1.10
192.168.1.20
Now I'm getting the Serial number and Name of the device with two commands:
wName=$(parallel adb -s {} shell getprop ro.product.display_name ::: "$wIP");
wSerial=$(parallel adb -s {} shell getprop ro.serialno ::: "$wIP");
Result from $wName is:
Samsung Watch4
Samsung Watch4
Result from $wSerial is:
RFAR82JDGLJ
RFAR82JPRFC
For printing I use this commands:
printf "%-22s %-22.27s %-14.12s\n" "IP" "Name" "Serial"
printf "%-22s %-22.27s %-14.14s\n" "$wIP" "$wName" "$wSerial"
Final matching is:
IP Name Serial
192.168.1.10 Samsung Watch4 RFAR82JDGLJ
192.168.1.20 Samsung Watch4 RFAR82JPRFC
Question: How to get in "Name" in brackets last 4 characters from "Serial" and get result like this:
IP Name Serial
192.168.1.10 Samsung Watch4 (DGLJ) RFAR82JDGLJ
192.168.1.20 Samsung Watch4 (PRFC) RFAR82JPRFC
Complete code:
wIP=$(adb devices | tail -n +2 | grep "device" | cut -f1 | cut -f1 -d\ );
wName=$(parallel adb -s {} shell getprop ro.product.display_name ::: "$wIP");
wSerial=$(parallel adb -s {} shell getprop ro.serialno ::: "$wIP");
printf "%-22s %-22.27s %-14.12s\n" "IP" "Name" "Serial"
printf "%-22s %-22.27s %-14.14s\n" "$wIP" "$wName" "$wSerial"