Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • That’s definetly helpful. Thanks! I’m still somewhat unhappy with all linebreaks being gone in the output, though. Is there a way to reinsert them (e.g. at “…line 23.Reference…”), so all occurences of “Reference” start at a new line? What I get is this: Reference duiarneutdigane uditraenturida enudtiar.Reference uiae uiaetrtdnsu iatdne uiatrdenu diaren uidtae <newline> on line 23.Reference uriadne udtiraeb unledut iaeru uilaedr uiarnde line 234. Commented Feb 19, 2017 at 10:13
  • @bleistift2, with -z the output terminator is also \0 (the null char); several unix commands alsa have a -z to define that input or output is null separated. Commented Feb 19, 2017 at 10:56
  • 1
    With some more try’n’error I found this really simple solution: grep -zoP '(?s)Reference.*?\.\n?' tst. By matching the \n at the end of the line, I get line breaks in the output: Reference duiarneutdigane uditraenturida enudtiar.<newline> Reference uiae uiaetrtdnsu iatdne uiatrdenu diaren uidtae <newline> on line 23. <newline> Reference uriadne udtiraeb unledut iaeru uilaedr <newline> uiarnde line 234. The ending line break needs to be optional, else the last line wouldn’t match, since there is no newline preceding the end of file. Thank you for your help @JJoao and vatsug Commented Feb 19, 2017 at 11:11