fork download
  1. /\\section{/ { oldline=$0
  2. if ( oldline ~ /}/ ) {
  3. lt=gensub(".*{([^}]+)}.*","\\1","g",oldline)
  4. } else {
  5. lt=gensub(".*{(.*)","\\1","g",oldline)
  6. getline tmp
  7. while ( tmp !~ "}" ) {
  8. lt=lt "\n" tmp
  9. getline tmp
  10. }
  11. lt=lt "\n" gensub("}.*","","g",tmp)
  12. }
  13. getline
  14. while ( $0 !~ /\\sectionmark/ ) {
  15. getline
  16. }
  17. printf("\\section[%s]{%s%s}\n",lt,lt,$0)
  18. getline
  19. }
  20. ! /\\section{/ { print }
Success #stdin #stdout 0.02s 4276KB
stdin
OTHERTEXT_1
\section{long text}
\sectionmark{short text}
OTHERTEXT_2
\section{long text
with new
lines}
\sectionmark{short text}
OTHERTEXT_3
\section{long text with empty line afterwards}

\sectionmark{short text}
OTHERTEXT_4
\section{long text
with new
lines and an empty line afterward}

\sectionmark{short text}
OTHERTEXT_5
stdout
OTHERTEXT_1
\section[long text]{long text\sectionmark{short text}}
OTHERTEXT_2
\section[long text
with new
lines]{long text
with new
lines\sectionmark{short text}}
OTHERTEXT_3
\section[long text with empty line afterwards]{long text with empty line afterwards\sectionmark{short text}}
OTHERTEXT_4
\section[long text
with new
lines and an empty line afterward]{long text
with new
lines and an empty line afterward\sectionmark{short text}}
OTHERTEXT_5