Offsets for CLI guru
This commit is contained in:
parent
2ba9341739
commit
f5e181c272
1 changed files with 22 additions and 0 deletions
22
bin/offset
Executable file
22
bin/offset
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
#!/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))"
|
||||
Loading…
Add table
Add a link
Reference in a new issue