Good evening everyone!
You need to write a regular expression that selects a line from the file and the lines following it, before the next key

For example, in the file a lot of different keys are described:

/P Π’Ρ‹Π²ΠΎΠ΄ запросов ΠΏΠ΅Ρ€Π΅Π΄ созданиСм ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ Π½ΠΎΠ²ΠΎΠ³ΠΎ Ρ„Π°ΠΉΠ»Π°. /S ΠšΠΎΠΏΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ нСпустых ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ΠΎΠ² с ΠΏΠΎΠ΄ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π°ΠΌΠΈ. /E ΠšΠΎΠΏΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ΠΎΠ² с ΠΏΠΎΠ΄ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π°ΠΌΠΈ, Π²ΠΊΠ»ΡŽΡ‡Π°Ρ пустыС. Π­ΠΊΠ²ΠΈΠ²Π°Π»Π΅Π½Ρ‚Π΅Π½ ΡΠΎΡ‡Π΅Ρ‚Π°Π½ΠΈΡŽ ΠΊΠ»ΡŽΡ‡Π΅ΠΉ /S /E. БовмСстим с ΠΊΠ»ΡŽΡ‡ΠΎΠΌ/T. /C ΠŸΡ€ΠΎΠ΄ΠΎΠ»ΠΆΠ΅Π½ΠΈΠ΅ копирования Π²Π½Π΅ зависимости ΠΎΡ‚ наличия ошибок. 

I use the command FINDSTR /C: "/E " file.txt > lab.txt

With such an entry in the file will display the following line:

 /E ΠšΠΎΠΏΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ΠΎΠ² с ΠΏΠΎΠ΄ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π°ΠΌΠΈ, Π²ΠΊΠ»ΡŽΡ‡Π°Ρ пустыС. 

and I need to get it out:

 /E ΠšΠΎΠΏΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ΠΎΠ² с ΠΏΠΎΠ΄ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π°ΠΌΠΈ, Π²ΠΊΠ»ΡŽΡ‡Π°Ρ пустыС. Π­ΠΊΠ²ΠΈΠ²Π°Π»Π΅Π½Ρ‚Π΅Π½ ΡΠΎΡ‡Π΅Ρ‚Π°Π½ΠΈΡŽ ΠΊΠ»ΡŽΡ‡Π΅ΠΉ /S /E. БовмСстим с ΠΊΠ»ΡŽΡ‡ΠΎΠΌ/T. 

Ie to get 2 lines and if there are 3 of them in the key, then 3 is described

Question: how to change the regular expression? command key to change to FINDSTR /R "рСгулярноС Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅" file.txt > file2.txt

    1 answer 1

    FINDSTR not able to search for multi-line matches (unless you refer to dark hacks ). It would be possible to use JREPL.bat , but, in my opinion, he is not on friendly terms with Russian. So I can advise pcregrep (there is a port under Windows pcregrep ):

     pcre2grep -M "^/E .+(\r?\n .+)*" file.txt 
    • I downloaded grep.exe, threw it into System32, I launch the console, I go to the directory where my file is located, I write grep -M "^ / E. + (\ r? \ n. +) *" file.txt> text.txt, but it doesn't send anything to the file, the file is empty - Ozma
    • there you need to take into account that there are two spaces in front of the key / E - Ozma
    • Thank you very much, thanks to you, it turned out, I did this like grep -A 1 "/ E" file.txt> text.txt, where -A 1 is the number of lines after the found line to be output - Ozma