10 comments

[ 29.0 ms ] story [ 310 ms ] thread
.

   test -f "$1" -a "$2" ||
   exec echo "usage: grep [options] -bo PATTERNS FILE|${0##*/} FILE len [+/- left] [+/- right]"

   #grep -f PATTERNFILE FILE|${0##*/} FILE len [+/- left] [+/- right]"

   #grep -m100 -bo PATTERNS FILE|tail -1|${0##*/} FILE len [+/- left] [+/- right]"

   cut -d: -f1 \
   |while read k
    do
    j=$(printf 0x%x\\n "$k")
    echo "s$(($j-${3-0}))";
    echo "b$((  ${3-0}+${4-0}+$2 ))";
    echo X;
    done \
   |ired -n "$1" \
   |tr -cd '[ -~\n]' \
   |sed 's/.*/w&0a/' \
   |ired -n /dev/stdout 

   #r ipgrep needs "-N" and "--color never" to match speed of GNU grep
(comment deleted)
(comment deleted)
(comment deleted)
(comment deleted)
(comment deleted)
(comment deleted)
(comment deleted)
HN comment formatting not working

   cut -d: -f1|while read k;do j=$(printf 0x%x\\n "$k");echo "s$(($j-${3-0}))";echo "b$((${3-0}+${4-0}+$2))";echo X;done|ired -n "$1"|tr -cd '[ -~\n]'|sed 's/.*/w&0a/'|ired -n /dev/stdout
If not using any other grep options, e.g., reading patterns or fixed strings from file, then something like

   test "$#" -gt 1||exec \
   echo "usage: ${0##*/} PATTERN FILE [+/- left] [+/- right]"
   test -f "$2" ||exit
   i="${#1}"
   grep -bo "$1" "$2" \
   |cut -d: -f1 \
   |while read k
    do
    j=$(printf 0x%x\\n "$k")
    echo "s$(($j-${3-0}))";
    echo "b$((  ${3-0}+${4-0}+$i ))";
    echo X;
    done \
   |ired -n "$2" \
   |tr -cd '[ -~\n]' \
   |sed 's/.*/w&0a/' \
   |ired -n /dev/stdout