-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbyte_range
More file actions
executable file
·45 lines (34 loc) · 850 Bytes
/
Copy pathbyte_range
File metadata and controls
executable file
·45 lines (34 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
__track_usage "$(basename "$0")"
# byte_range $start $end
# - Outputs the bytes between the starting and ending values from the stdin stream
#
# - $start - Starting byte to display
# - $end - Ending byte to display
isInteger() {
local regex_numeric='^[0-9]+$'
[[ "$1" =~ $regex_numeric ]]
}
byteRange() {
local start="$1"
local length="$2"
tail -c +"$start" | head -c "$length"
}
checkInputs() {
local start="$1"
local end="$2"
if ! isInteger "$start" || ! isInteger "$end"; then
echo "Non-integer provided as input. Exiting"
exit 1
fi
if [ $start -ge $end ]; then
echo "Starting value must be less than ending value"
exit 1
fi
}
diff() {
echo "$1 - $2" | bc
}
checkInputs "$1" "$2"
START="$1"; END="$2"; LENGTH=$(diff "$END" "$START");
cat - | byteRange "$START" "$LENGTH"