1
0
Fork 0
dotfiles/bin/offset
2019-02-06 11:30:27 -08:00

22 lines
398 B
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
if [ "$#" -lt 3 ]; then
cat <<-USAGE
Usage: $0 filename line column
USAGE
exit 1
fi
fname="$1"
linum="$(("$2"))"
beforelines="$((linum - 1))"
colnum="$3"
beforecols="$((colnum - 1))"
offset=$({
head --quiet --lines "$beforelines" "$fname"
sed -n "${linum}p" "$fname" | awk '{ print substr($0,0,'"$beforecols"') }'
} | wc -c)
echo "$((offset - 1))"