On Sun, Jul 24, 2022 at 10:34:04AM -0700, Andrew Hewus Fresh wrote: > I'll try to think about whether I can build a sed program that will > spit out matches.
Unfortunately the sed version seems to be even slower than matching one line at a time. Just building the patterns for sed is slower than the original single match. --- fw_update.sh.orig Sun Jul 24 10:07:40 2022 +++ fw_update.sh Sun Jul 24 20:50:02 2022 @@ -168,22 +168,34 @@ } firmware_in_dmesg() { - local _d _m _line _dmesgtail _last='' _nl=$( echo ) + local _cmd - # The dmesg can contain multiple boots, only look in the last one - _dmesgtail="$( echo ; sed -n 'H;/^OpenBSD/h;${g;p;}' /var/run/dmesg.boot )" - - grep -v '^[[:space:]]*#' "$FWPATTERNS" | + _cmd="$( grep -v '^[[:space:]]*#' "$FWPATTERNS" | ( + _s='/^%s/i\\\n%s\n' + _last= + _patterns= while read -r _d _m; do - [ "$_d" = "$_last" ] && continue - [ "$_m" ] || _m="${_nl}${_d}[0-9] at " - [ "$_m" = "${_m#^}" ] || _m="${_nl}${_m#^}" + [ "$_m" ] || _m="^${_d}[0-9] at " + [ "$_m" = "${_m#*/}" ] || _m="$( printf "$_m" | sed 's,/,\\/,g' )" - if [[ $_dmesgtail = *$_m* ]]; then - echo "$_d" - _last="$_d" + if [ "$_patterns" ] && [ "$_d" != "$_last" ]; then + printf "$_s" "$_patterns" "$_last" + _last= + _patterns= fi + + _last="$_d" + if [ "$_patterns" ]; then + _patterns="$_patterns|$_m" + else + _patterns="$_m" + fi done + [ "$_patterns" ] && printf "$_s" "$_patterns" "$_last" + ) )" + + # The dmesg can contain multiple boots, only look in the last one + sed -n 'H;/^OpenBSD/h;${g;p;}' /var/run/dmesg.boot | sed -En "$_cmd" } firmware_filename() {