Extract value between two strings in batch using a CSV file

137 Views Asked by At

I have a CSV file which contains multiple columns. One of these columns is HTML content. My first step is to search for &lt;&lt;&lt; and replace it with <<< - secondly I'm searching for &gt;&gt;&gt; and replace it with >>>.

My goal is to create an array in batch. For this procedure I would like to search for all elements which look like the scheme above <<<VALUE>>> and create an array.

I found the following code but it doesn't work for me...

for /F "tokens=1-2 delims=<<<>>>-" %%a in (temp.csv) do (@echo %%a %%b) 

Any suggestions?

UPDATE:

I would like to use regular expressions now, but this doesn't work either...

for /f %%x in ("temp.csv") do (
  echo %%x | findstr /r "^<^<^<^(\.\?\*^)^>^>^>"
)

...any help? :)

kind regards, markus

1

There are 1 best solutions below

0
On

I'm using now the simple tool batchRex.exe from administrator.de with an regular expression. I'm using the pattern <<<(.*?)>>> to get my values and save them to an .txt file. Afterwards I read line by line from this file into an array to work further on - just in case someone has the same problem ;-)

kind regards

markus