-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpi-diff.sh
More file actions
24 lines (17 loc) · 782 Bytes
/
pi-diff.sh
File metadata and controls
24 lines (17 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash
# Define the two files
file1="Pi-1000000.txt"
file2="pi.txt"
# Use cmp to find the byte position of the first difference
diff_pos=$(cmp -l $file1 $file2 | awk 'NR==1{print $1}')
if [[ -n $diff_pos ]]; then
# Decrement diff_pos by 5 to start displaying characters 5 positions before the difference
let "start_pos=$diff_pos-6 > 0 ? $diff_pos-6 : 0"
# Display ten characters from each file starting from start_pos
echo "Difference found at position: $diff_pos"
echo "Displaying ten characters from each file starting five chars before the difference..."
dd if=$file1 bs=1 count=10 skip=$start_pos 2>/dev/null | od -An -c
dd if=$file2 bs=1 count=10 skip=$start_pos 2>/dev/null | od -An -c
else
echo "No differences found."
fi