Skip to content

Instantly share code, notes, and snippets.

@capezotte
Last active December 27, 2022 02:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save capezotte/4378195e554fb353480f0635c3dc8eeb to your computer and use it in GitHub Desktop.
Save capezotte/4378195e554fb353480f0635c3dc8eeb to your computer and use it in GitHub Desktop.
fmt -w600, sed edition
#!/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