Skip to content

Commit

Permalink
Changed to egrep (faster)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlhonora committed Nov 4, 2013
1 parent 2797f8c commit 2644688
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lsusb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ done
# Each entry will be separated by two '--' lines. We replace them
# with the '#' symbol in case other parameters that contain a dash
# will not be interfered
devices=`grep -B 2 -A 6 "Product ID" sp_info.log | sed 's/^--/#/'`
devices=`egrep -B 2 -A 6 "Product ID" sp_info.log | sed 's/^--/#/'`

# Change the IFS to #, backup the current one
OIFS=$IFS
Expand All @@ -63,17 +63,17 @@ for device in $devices
do
# Get the name of the device, it is the first line that ends with a ':'
# Trim the string at the end
name=`echo $device | head -2 | grep ":$" | sed -e 's/^ *//g' -e 's/ *:$//g'`
name=`echo $device | head -2 | egrep ":$" | sed -e 's/^ *//g' -e 's/ *:$//g'`

# Get the PID, trim at the end
PID=`echo $device | grep "Product ID" | awk -F':' '{print $2}' | sed -e 's/0x//; s/^ *//g' -e 's/ *$//g'`
PID=`echo $device | egrep "Product ID" | awk -F':' '{print $2}' | sed -e 's/0x//; s/^ *//g' -e 's/ *$//g'`
# If there's no PID then we skip the entry
if [ -z "$PID" ]; then
continue
fi

# Get the VID, trim at the end
VID_all=`echo $device | grep "Vendor ID" | awk -F':' '{print $2}' | sed -e 's/0x//; s/^ *//g' -e 's/ *$//g'`
VID_all=`echo $device | egrep "Vendor ID" | awk -F':' '{print $2}' | sed -e 's/0x//; s/^ *//g' -e 's/ *$//g'`
# If there's no VID then we skip the entry
if [ -z "$VID_all" ]; then
continue
Expand Down Expand Up @@ -104,13 +104,13 @@ do

# Get the bus number. For that, grep the last entry that contains "Bus Number" and then trim at the end.
# Also remove the 0x from hex numbers
bus_num=`grep -B 100 "$PID" sp_info.log | grep "Bus Number" | tail -1 | sed -e 's/Bus Number://' -e 's/0x//; s/^ *//g' -e 's/ *$//g'`
bus_num=`egrep -B 100 "$PID" sp_info.log | egrep "Bus Number" | tail -1 | sed -e 's/Bus Number://' -e 's/0x//; s/^ *//g' -e 's/ *$//g'`
# Get the device number within the bus, print it as the second entry using '/' as field separator
device_num=`echo $device | grep "Location ID" | sed -e 's/Location ID://; s/^ *//g; s/ *$//g;' | awk -F'/' '{print $2}'`
device_num=`echo $device | egrep "Location ID" | sed -e 's/Location ID://; s/^ *//g; s/ *$//g;' | awk -F'/' '{print $2}'`

# Include serial number only if available
serial_str=""
serial_number=`echo $device | grep "Serial Number" | sed 's/Serial Number: //; s/^ *//g; s/ *$//g'`
serial_number=`echo $device | egrep "Serial Number" | sed 's/Serial Number: //; s/^ *//g; s/ *$//g'`
if [ -n "$serial_number" ]; then
serial_str=" Serial: $serial_number"
fi
Expand Down

0 comments on commit 2644688

Please sign in to comment.