I just see some regex could not work in windows cmd because it doesn't support all regex commands. I've found a regex for my problem.
So now I need to use findstr
with this regex: (?si)(?:^(?<!.)|\R{2}|^Account:(?-s:.*)\R)\K(?:(?!\R{2}).)*?(?-s:\bfifa\b.*\b20\b).*?(?=\R{2}|\z)
, but windows command line can't find this, and actually skips.
- How can I use above regex, to find all matches from a txt file and output them to another txt file in a batch file?
This is how I used to do it with other simple regex, but not working now:
type %LogFILE% | findstr /i /r /c:"(?si)(?:^(?<!.)|\R{2}|^Account:(?-s:.*)\R)\K(?:(?!\R{2}).)*?(?-s:\bfifa\b.*\b20\b).*?(?=\R{2}|\z)" > %LogNEW%
- Can we use powershell commands in cmd? I tried to do but it closes my batch command (I don't know is this correct syntax or no):
powershell -command "& {Get-ChildItem -Path .\LogFILE.txt -r | Select-String "(?si)(?:^(?<!.)|\R{2}|^Account:(?-s:.*)\R)\K(?:(?!\R{2}).)*?(?-s:\bfifa\b.*\b20\b).*?(?=\R{2}|\z)" > LogNEW.txt}"
EDITED: I want to select hits including fifa (as string not a single word) from a txt file, and output them to another txt file (separate solutions for 1 and 2 pattern):
Pattern 1 Solved:
powershell -command "& {Get-ChildItem .\LogFILE.txt -r | Get-Content -Raw | Foreach-Object { $_ -Split '(\r?\n)(?=(\r?\n)+)' } | Select-String 'fifa'} | Out-File -encoding Default LogNEW.txt"
1:
Region: AR
OnlineID: Atl_Tuc
---Start---
FIFA 18 Legacy Edition
---END---
Region: FR
OnlineID: jubtrrzz
---Start---
FIFA 19
Undertale
Pro Evolution Soccer™ 2018
---END---
Region: US
OnlineID: Cu128yi
---Start---
KINGDOM HEARTS HD 1.5 +2.5 ReMIX
---END---
Region: RO
OnlineID: Se116
---Start---
Real Farm
EA SPORTS™ FIFA 20
LittleBigPlanet™ 3
---END---
Region: US
OnlineID: CAJ5Y
---Start---
Madden NFL 18: G.O.A.T. Super Bowl Edition
---END---
Pattern 2 Solved: powershell -command "& {Get-ChildItem .\LogFILE.txt -r | Get-Content -Raw | Foreach-Object { $_ -Split '(?<=---END---\s*\n)\s*\n' } | Select-String 'fifa'} | Out-File -encoding Default LogNEW.txt"
2:
Language: pt-BR (Actually I need [Language:.*])
Region: AR
OnlineID: Atl_Tuc
---Start---
FIFA 18 Legacy Edition
---END---
Language: en-US
Region: FR
OnlineID: jubtrrzz
---Start---
FIFA 19
Undertale
Pro Evolution Soccer™ 2018
---END---
Language: en-GB
Region: US
OnlineID: Cu128yi
---Start---
KINGDOM HEARTS HD 1.5 +2.5 ReMIX
---END---
Language: pt-BR
Region: RO
OnlineID: Se116
---Start---
Real Farm
EA SPORTS™ FIFA 20
LittleBigPlanet™ 3
---END---
Language: es-MX
Region: US
OnlineID: CAJ5Y
---Start---
Madden NFL 18: G.O.A.T. Super Bowl Edition
---END---