~kris/dots

srice

ref: a71a43ca650266b35ee4946352b54d8f7365fda7 srice/.local/bin/kwic -rwxr-xr-x 314 bytes
a71a43ca — Kris Yotam profile: export ENV so interactive mksh loads ~/.mkshrc 3 months ago
                                                                                
1
2
3
4
5
6
7
8
#!/usr/bin/env bash
# kwic -- KWIC concordancer
# Usage: kwic <pattern> <file> [context_words]
pattern="${1:?Usage: kwic <pattern> <file> [context_words]}"
file="${2:?Provide a file}"
ctx="${3:-5}"
grep -oP "(\S+\s+){0,$ctx}\S*${pattern}\S*(\s+\S+){0,$ctx}" "$file" | \
    sed "s/${pattern}/\x1b[1;31m&\x1b[0m/g"