BEGIN { line=0; } NR==1,/Amalie Skram\. I\./ { next } # Footer /^ *[0-9]* *Constance *Ring *[0-9]* *$/ { next } /^(II*|IV)\.?$/ { print "# " $0 next } { # Format paragaph starts gsub(/^ /, "\n") # Remove leading space gsub(/^ */, "") print }