Last active
December 27, 2022 02:20
-
-
Save capezotte/4378195e554fb353480f0635c3dc8eeb to your computer and use it in GitHub Desktop.
fmt -w600, sed edition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/sed -nf | |
# First line: only hold and skip. | |
1 { h;d; } | |
# Line with only spaces: wow, free paragraph information! | |
/^\s*$/ { s/^.*$//; bfinished } | |
# Append line to hold space. | |
H | |
# Line ends with dot? We have a new paragraph. | |
/\.$/bfinished | |
# Render last line | |
$bfinished | |
# If we didn't branch to finish, then skip. | |
# We already have held the pattern anyway. | |
d | |
:finished | |
# One of the above conditions happened. Let's roll. | |
# Get hold space | |
x | |
# Handle hyphenation | |
s/-\n//g | |
# Delete newlines | |
s/\n/ /g | |
# Add some paragraphing | |
a\ | |
# Print hold space | |
p | |
# Empty hold space | |
s/.*//g | |
# Get old pattern space | |
x | |
# Squeeze empty lines. | |
:spacefind | |
n | |
/^\s*$/bspacefind | |
# Hold first non-space only line | |
h |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment