sed print from match until other match NOT inclusive

Marceau

I want to print all lines from a match up to a second match, not including that second match.

What I have so far does everything and does too much, in that it prints the second match as well.

Specifically, let's say I want to print everything starting on a line containing 'test', up to, but not including, the first line starting with a number or an open bracket '['.

This goes some way, but not all the way:

sed -n '/test/,/^[0-9]\|^\[/p' file
anubhava

It is much easier to do this via awk:

awk '/test/{p=1} /^([0-9]|\[)/{p=0} p' file

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Replace with sed until match in a line

From Dev

Print lines from match until end of file with awk

From Dev

awk + print lines from the first line until match word

From Dev

Print last match of a sed regex

From Dev

sed replace in file until pattern match

From Dev

sed replace in file until pattern match

From Dev

Get proceeding lines after match until lines match other pattern

From Dev

Print from Nth match to Mth match

From Dev

Sed : print all lines after match

From Dev

Sed to print only first pattern match of the line

From Dev

How to remove the lines from the matched string until the next match using sed command

From Dev

Regex: match everythin from : until \n or <br />

From Dev

extract lines from bottom until regex match

From Dev

Regex match from pattern until another pattern

From Dev

Sed or Grep to replace until end of line after pattern match

From Dev

Different match results from grep and sed

From Dev

Output each match from sed as a separate file

From Dev

print all line that match my pattern until last end pattern match

From Dev

Can I multiply pattern match in SED address to print

From Dev

Print previous line after a pattern match using sed?

From Dev

sed script to print n lines after the last occurence of a match

From Dev

How to show lines after each grep match until other specific match?

From Dev

Match until with priority

From Dev

Regex match until "&" or "|"

From Dev

Match everything until a pattern

From Dev

Match until with priority

From Dev

Print the word after match from Perl array

From Dev

trying to print a group from a regex match in python

From Dev

How to print the result of the match from strpos in php

From Dev

match and print multiple columns from two files

Related Related

  1. 1

    Replace with sed until match in a line

  2. 2

    Print lines from match until end of file with awk

  3. 3

    awk + print lines from the first line until match word

  4. 4

    Print last match of a sed regex

  5. 5

    sed replace in file until pattern match

  6. 6

    sed replace in file until pattern match

  7. 7

    Get proceeding lines after match until lines match other pattern

  8. 8

    Print from Nth match to Mth match

  9. 9

    Sed : print all lines after match

  10. 10

    Sed to print only first pattern match of the line

  11. 11

    How to remove the lines from the matched string until the next match using sed command

  12. 12

    Regex: match everythin from : until \n or <br />

  13. 13

    extract lines from bottom until regex match

  14. 14

    Regex match from pattern until another pattern

  15. 15

    Sed or Grep to replace until end of line after pattern match

  16. 16

    Different match results from grep and sed

  17. 17

    Output each match from sed as a separate file

  18. 18

    print all line that match my pattern until last end pattern match

  19. 19

    Can I multiply pattern match in SED address to print

  20. 20

    Print previous line after a pattern match using sed?

  21. 21

    sed script to print n lines after the last occurence of a match

  22. 22

    How to show lines after each grep match until other specific match?

  23. 23

    Match until with priority

  24. 24

    Regex match until "&" or "|"

  25. 25

    Match everything until a pattern

  26. 26

    Match until with priority

  27. 27

    Print the word after match from Perl array

  28. 28

    trying to print a group from a regex match in python

  29. 29

    How to print the result of the match from strpos in php

  30. 30

    match and print multiple columns from two files

HotTag

Archive