All pastes #34015 Raw Edit

sed script

public text v1 · immutable
#34015 ·published 2005-12-18 01:03 UTC
rendered paste body
#!/usr/bin/sed -f
:loop
  # Remove leading uninteresting stuff
  s/^[^[]*//

  # If we didn't hit a math start yet, get next line
  /^\[\[/! d

  # We now have a string starting with [[
  # Until we have a starting and an ending point, get more lines
  :get
  /\[\[.*\]\]/ bgot
  N
  bget
  :got

  # We now have a string containing at least one string we want
  # Preserve in hold space
  h
  # Remove everything not inside the pattern and print it
  s/^\(\[\[[^]]*\]\]\).*/\1/p
  # get text back from hold space
  g
  # Remove just-printed string
  s/^\[\[[^]]*\]\]//
bloop