How can I read a braces delimited text file in a Windows batch file?

I have the file txt having some lines , and here below is my txt file

rule.txt ---------------------------------------- direct replace{100,1011} replace{india,o891} replace{1100,101} ----------------------------------------- 

I need to capture the numbers in between open braces and closed brace using batch file.

2

2 Answers

With a batch-file:

:: Q:\Test\2018\12\26\SU_1387726.cmd @Echo off For /F "tokens=2,3 delims={,}" %%A IN ( ' findstr "{" rule.txt' ) DO ECHO:%%A =^> %%B 

sample output:

> Q:\Test\2018\12\26\SU_1387726.cmd 100 => 1011 india => o891 1100 => 101 

If you are trying to capture the data inside the curly braces then you may use the following powershell command.

Get-ChildItem rule.txt | Select-String -Pattern '(?<={).*?(?=})' | % { $_.Matches } | % { $_.Value } 

Output

100,1011 india,o891 1100,101 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like