4359 links
  • Arnaud's links
  • Home
  • Login
  • RSS Feed
  • ATOM Feed
  • Tag cloud
  • Picture wall
  • Daily
Links per page: 20 50 100
  • thumbnail
    shell - How to select lines between two marker patterns which may occur multiple times with awk/sed - Stack Overflow

    Use awk with a flag to trigger the print when necessary:

    $ awk '/abc/{flag=1;next}/mno/{flag=0}flag' file
    def1
    ghi1
    jkl1
    def2
    ghi2
    jkl2

    How does this work?

    /abc/ matches lines having this text, as well as /mno/ does.
    /abc/{flag=1;next} sets the flag when the text abc is found. Then, it skips the line.
    /mno/{flag=0} unsets the flag when the text mno is found.
    The final flag is a pattern with the default action, which is to print $0: if flag is equal 1 the line is printed.

    For a more detailed description and examples, together with cases when the patterns are either shown or not, see How to select lines between two patterns?.

    November 5, 2018 at 4:42:37 PM GMT+1 - permalink - archive.org - https://stackoverflow.com/questions/17988756/how-to-select-lines-between-two-marker-patterns-which-may-occur-multiple-times-w
    awk
Links per page: 20 50 100
Shaarli - The personal, minimalist, super fast, database-free, bookmarking service by the Shaarli community - Help/documentation