SHARE
TWEET

one_line_paragraphs

amphoterrific Aug 14th, 2019 (edited) 4 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # vim: ft=zsh
  2. #script to reformat text that uses hard line wrapping
  3. #
  4. #output text is formatted so each paragraph is a single line,
  5. #in order to make text flow properly when placed in programs like indesign
  6. #
  7. #input text should be formatted so that paragraphs are separated by one or more blank lines
  8.  
  9. cat -s <$1 >.onelinpar1
  10. # squeezes multiple blank lines into one blank line
  11.  
  12. sed -r -e '/^[[:blank:]]*$/s/^.*$/----/' -e '/^[[:blank:]]/s/^[[:blank:]]+//' <.onelinpar1 >.onelinpar2
  13. # fill blank lines with four dashes each
  14.  
  15. sed '/^----/s/$/\n----/' <.onelinpar2 >.onelinpar3
  16.  
  17. sed -e '
  18.     :A
  19.     /^[^-]/{
  20.     N
  21.     /\n[^-]/{
  22.     s/\n/ /
  23.     }
  24.     }
  25.     tA
  26. ' <.onelinpar3 >.onelinpar4
  27.  
  28. sed '/^----$/d' <.onelinpar4 >"${1}-formatted"
  29.  
  30. rm .onelinpar*
  31. # removes temp files
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top