Skip to content

Instantly share code, notes, and snippets.

@hraban
Last active June 3, 2024 08:45
Show Gist options
  • Select an option

  • Save hraban/b994bf3adbae56e2d73160ea298c925c to your computer and use it in GitHub Desktop.

Select an option

Save hraban/b994bf3adbae56e2d73160ea298c925c to your computer and use it in GitHub Desktop.
demonstration of difference splitting on spaces and splitting every 50 (SU/a/496421)

Demonstration of the difference between approaches https://superuser.com/a/663694/442895 and https://superuser.com/a/496421/442895 :

The test files were generated with:

$ </dev/random base64 | tr -s \\n \  | head -c 1000000 > file1.txt

For file2.txt I copied file1.txt and manually removed the 800th and the 80th characters.

First solution

$ diff -u <(tr -s \  \\n <file1.txt ) <(tr -s \  \\n <file2.txt)
--- /dev/fd/63	2024-06-03 04:21:07
+++ /dev/fd/62	2024-06-03 04:21:07
@@ -1,5 +1,5 @@
 ZJ0LMAnZ8Iq2R1Y8gK347sSXc8xsOCPbDeliBd/v/ncwZN8XgxleqDK+JvpZXY3lCyDq1bey+4Z/
-5Mx8Nf3VzZFQnSHnXg+ZCXDO+roB/6NYsIomK0HE8u7yNij76rlSkPb+H7dnD4IxHhECBPsaH9V2
+5M8Nf3VzZFQnSHnXg+ZCXDO+roB/6NYsIomK0HE8u7yNij76rlSkPb+H7dnD4IxHhECBPsaH9V2
 a/TXrK09x4mEFO4p1FP+k4wDB3aUTKlQ7re1E3AentxeC4tWs8nxzyAGQjIlwLDvGBxmfb/xaa5+
 nHfXjMwMOdknGzeza3SFJqTtRISV1fGNWAfvil72bFSYnOeOHegBMxgzofaBt6ApVEi/38jNWFBY
 5tvuCSwALVi/m4pkG8eAeXNWUNbuk+Xa9odv8Fs2X9ssQyM9DNhyEcDSD3GVXRwRfeZG8AlWvxSE
@@ -8,7 +8,7 @@
 kcpQaW8dEWcfFl/C8TWDp21BW6LnAF62tI7Aj3ximOKDFWbkovvbmjymUAVTmEaZfPYO8YndsuM3
 JUefUMjnsk1RQxE0GlcMQSe4Cf35bfFncHlA8rKvtC4jkPneFCZuteF+zH+WHwXgMZLFRMgUTNfQ
 IwXXJBPC8tr47wNZOiU6OqigxMNYZZnxaTwp+wqPI5si15YgfGHyyRLSZGndQ4DNGUfc9LJB7W/j
-N9IVsMjcknx5w4nCSgXT4tx3s8FDAJOZ/puGVG7XJVWlRSTyody/cLqDpByGHwzKvfwEwhaoLubb
+N9IVsMjcknx5w4nCSgXT4tx3s8FDAOZ/puGVG7XJVWlRSTyody/cLqDpByGHwzKvfwEwhaoLubb
 higduKjMNhVDtFWJtbPZwDxUha2a+GNKKbCU0nZvWGNws4pW5e14GLrjsbPHtVhzDZLfAxVckQ6F
 JL+sGyLSFvnl0c5qaaVdGMj+K3CmnGqVSfxcH4i53xY+RwK6DJ3EGielmIEv3PjY40Ky99rLckQu
 26Q6OjwStSBeETQ5panFlpu5lvyolZRK7l9dKl9VmpkMnynrb8IP6bsY/ErRLtmGOtsCkOlE7n3k

Second solution

$ diff -u <(./newline-every-50-chars.py file1.txt ) <(./newline-every-50-chars.py file2.txt)
--- /dev/fd/63	2024-06-03 04:22:16
+++ /dev/fd/62	2024-06-03 04:22:16
@@ -1,20000 +1,20000 @@
 ZJ0LMAnZ8Iq2R1Y8gK347sSXc8xsOCPbDeliBd/v/ncwZN8Xgx
-leqDK+JvpZXY3lCyDq1bey+4Z/ 5Mx8Nf3VzZFQnSHnXg+ZCXD
-O+roB/6NYsIomK0HE8u7yNij76rlSkPb+H7dnD4IxHhECBPsaH
-9V2 a/TXrK09x4mEFO4p1FP+k4wDB3aUTKlQ7re1E3AentxeC4
-tWs8nxzyAGQjIlwLDvGBxmfb/xaa5+ nHfXjMwMOdknGzeza3S
-FJqTtRISV1fGNWAfvil72bFSYnOeOHegBMxgzofaBt6ApVEi/3
-8jNWFBY 5tvuCSwALVi/m4pkG8eAeXNWUNbuk+Xa9odv8Fs2X9
(39992 lines omitted--see attached file)

It yields a very long diff.

This file has been truncated, but you can view the full file.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment