Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # colorize [-c ANSI] pattern
- #
- # Colorize text matching pattern with ANSI sequence (default is `31;1' for red-
- # bold). Non-matching lines are printed as-is.
- #
- colorize()
- {
- local OPTIND=1 OPTARG flag
- local ansi_color=
- while getopts c: flag; do
- case "$flag" in
- c) ansi_color="$OPTARG" ;;
- esac
- done
- shift $(( $OPTIND - 1 ))
- awk -v color="${ansi_color:-31;1}" -v pattern="$1" '
- (match($0, pattern) && $0 = sprintf("%s%c[%sm%s%c[0m%s",
- substr($0, 0, RSTART - 1), 27, color,
- substr($0, RSTART, RLENGTH), 27,
- substr($0, RSTART + RLENGTH))) || 1
- ' # END-QUOTE
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement