How to extract multiple line strings between two keywords using grepwin

user2329524

Hi I have a directory of files and each file has multiple languages text strings over multiple lines. Using grepwin I would like to extract all the English text strings and save into another text file. Typically in the each file the english text is inside a Switch/Case condition like this:

Default //English
    bitmap 8 20 "bmp5/warning.bmp"
    Ltext 5 1 11 "USB Device Overload"      
    LText 85 20 13 "USB"
    Ltext 50 33 13 "Device Overload!"
Break

Case _French
            bitmap 8 20 "bmp5/warning.bmp"
            LTEXT 5 1 11 "Surcharge clé USB!" 
            LTEXT 45 30 13 "Surcharge clé USB" 
Break 

Since all the English text is always between 'Default' and 'Break' I want to use those two keywords as the delimeter. Finally all the text between the two keywords needs to be saved out to another text file.

Can anyone help at all.

Thanks guys

Avinash Raj

Through grep.

$ grep -oPz '(?s)(?<=\n|^)Default\b[^\n]*\n\K.*?(?=\nBreak\b)' file
    bitmap 8 20 "bmp5/warning.bmp"
    Ltext 5 1 11 "USB Device Overload"      
    LText 85 20 13 "USB"
    Ltext 50 33 13 "Device Overload!"

To save the result to another file, you need to use output redirection operator.

grep -oPz '(?s)(?<=\n|^)Default\b[^\n]*\n\K.*?(?=\nBreak\b)' infile > outfile

From man grep

  -P, --perl-regexp         PATTERN is a Perl regular expression
  -z, --null-data           a data line ends in 0 byte, not newline

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to extract a word that occurs between two keywords on a line?

From Dev

Extract strings between two strings using Regex

From Dev

AWK: How to exactly match and print multiple words between two keywords in the same line

From Dev

How to extract a number between two different strings

From Dev

extract strings between two strings in python using regular expression

From Dev

Extract Code between two different new line strings

From Dev

Extract Code between two different new line strings

From Dev

Vbscript to Extract Data between two Keywords with RegExp

From Dev

Extract text between two strings repeating multiple times

From Dev

How to extract multiple strings from a line using SED regex in Linux and write them to a file?

From Dev

Extract Values between two strings in a text file using python

From Dev

extract strings between last two slashes using regular expression in javascript

From Dev

extract string between two strings from text document using AppleScript

From Dev

PHP: extract numbers between two strings using regex

From Dev

extract string between two strings from text document using AppleScript

From Dev

Extract string between two strings

From Dev

How can I extract the text between two strings in a log file?

From Dev

How to extract value between two strings with regexp_replace in Oracle?

From Dev

How to extract strings between two special different characters in TSQL

From Dev

regex extract list of strings between two strings

From Dev

How to extract between 2 strings when file contains multiple symbols

From Dev

How to remove a line break between two strings (RegEx)

From Dev

Command line tool that prints all strings between certain matched keywords

From Dev

How to merge unknown number of multiple lines between two patterns into a single line using awk

From Dev

How to search for a text between two patterns in one line with multiple occurrences using sed?

From Dev

How to extract two strings from url using regex?

From Dev

Extract two strings from a line of text with Ansible

From Dev

zsh: extract command line arguments into two strings

From Dev

Extract text between two strings on different lines

Related Related

  1. 1

    How to extract a word that occurs between two keywords on a line?

  2. 2

    Extract strings between two strings using Regex

  3. 3

    AWK: How to exactly match and print multiple words between two keywords in the same line

  4. 4

    How to extract a number between two different strings

  5. 5

    extract strings between two strings in python using regular expression

  6. 6

    Extract Code between two different new line strings

  7. 7

    Extract Code between two different new line strings

  8. 8

    Vbscript to Extract Data between two Keywords with RegExp

  9. 9

    Extract text between two strings repeating multiple times

  10. 10

    How to extract multiple strings from a line using SED regex in Linux and write them to a file?

  11. 11

    Extract Values between two strings in a text file using python

  12. 12

    extract strings between last two slashes using regular expression in javascript

  13. 13

    extract string between two strings from text document using AppleScript

  14. 14

    PHP: extract numbers between two strings using regex

  15. 15

    extract string between two strings from text document using AppleScript

  16. 16

    Extract string between two strings

  17. 17

    How can I extract the text between two strings in a log file?

  18. 18

    How to extract value between two strings with regexp_replace in Oracle?

  19. 19

    How to extract strings between two special different characters in TSQL

  20. 20

    regex extract list of strings between two strings

  21. 21

    How to extract between 2 strings when file contains multiple symbols

  22. 22

    How to remove a line break between two strings (RegEx)

  23. 23

    Command line tool that prints all strings between certain matched keywords

  24. 24

    How to merge unknown number of multiple lines between two patterns into a single line using awk

  25. 25

    How to search for a text between two patterns in one line with multiple occurrences using sed?

  26. 26

    How to extract two strings from url using regex?

  27. 27

    Extract two strings from a line of text with Ansible

  28. 28

    zsh: extract command line arguments into two strings

  29. 29

    Extract text between two strings on different lines

HotTag

Archive