Skip to content

Instantly share code, notes, and snippets.

@rjp
Last active April 18, 2016 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjp/8d70691a268be562f9c92a8baecb1344 to your computer and use it in GitHub Desktop.
Save rjp/8d70691a268be562f9c92a8baecb1344 to your computer and use it in GitHub Desktop.
# Highlight a span from a given block of characters
#
# usage: ./fillspan spanofcharacters min max
#
# e.g. ./fillspan 123456789ABCDEF 1 5 => [12345 ]
# ./fillspan 123456789ABCDEF 10 15 => [ ABCDEF]
# ./fillspan 123456789ABCDEF 5 9 => [ 56789 ]
bar=$1
min=$2
max=$3
blank=$(echo "$bar" | tr -c ' ' ' ')
premin=$((min-1))
len=$((max-min+1))
postmax=$((max+1))
echo "[${blank:0:$premin}${bar:$premin:$len}${blank:$postmax}]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment