I am hoping someone can help me with this issue.
I have a folder with multiple text files.
Each text files contains piped words/text between curly braces like this.....
{a|b|c|d} ....... {e|f|g|h} ........ {i|j|k|l|m} .....etc
OR sometimes nested curly braces like this....
{{a|b|c|{d|d1|d2|d3}}|{e|{f|f1|f2|f3}|g|h}|{i|j|k|{l|l1|l2|l3}|m}} ........... {{n|o|p|q}|{r|s|t|u}|{v|w|x|y|z}}
I need to extract all text strings between every {} and output to a single text file, each text string on a separate line.
The output needs to be in this format.....
a|b|c|d
d|d1|d2|d3
e|f|g|h
f|f1|f2|f3
i|j|k|l|m
l|l1|l2|l3
n|o|p|q
r|s|t|u
v|w|x|y|z
Any help to achieve this goal would be much appreciated.
Extract Text String Between Curly Braces From Multiple Files in a Directory And Save Extracted to File
Moderator: DosItHelp
Re: Extract Text String Between Curly Braces From Multiple Files in a Directory And Save Extracted to File
You could use JREPL.BAT.
Try that code
Steffen
Try that code
Code: Select all
@echo off &setlocal
(for %%i in (*.txt) do @for /f "delims={}" %%j in ('jrepl.bat "{[^{}]+}" "" /F "%%~i" /MATCH') do @echo %%j)|sort
pause
Steffen
-
- Posts: 16
- Joined: 25 Feb 2017 12:55
- Location: Russia
Re: Extract Text String Between Curly Braces From Multiple Files in a Directory And Save Extracted to File
Code: Select all
sed -r -e "s/(\x7b[^\x7b\x7d]{1,}\x7d)/\n\1\n/g" *.txt | sed -n "/^\x7b.*\x7d$/p" | sed "s/^\x7b//;s/\x7d$//" | sort>new.txt
-
- Posts: 118
- Joined: 02 Apr 2017 06:11
Re: Extract Text String Between Curly Braces From Multiple Files in a Directory And Save Extracted to File
As aGerman suggested using JREPL.bat is the solution. I suggest that you learn how to use JREPL as it will come handy in many cases when FINDSTR doesn't seem to work.