RedErdnuss
RedErdnuss

Reputation: 123

Grab specific Info from txt file

I have only experience with web scripting and cocoa (Mac), but not Windows programming, so I would be greatful for any help in producing a batch script or smt like that. I have textfiles where there is information like this

AlexanderWelten*FI3FFK!duZ1
Daten: Alexander Welten<br />Abrahamstr. 22<br />18472 Berlin<br />Deutschland
Maddiiiiin*hg72152aaf
Daten: Martin Loob<br />Welzstr. 12<br />52621 Frankfurt<br />Deutschland
ricki1991*super112X
Daten: Lars Ulbrich<br />Azurstr. 51<br />72223 Bonn<br />Deutschland
......

The "<br />" can be ignored, it is not effective HTML, so no linebreak, I will replace it with ", " anyway soon. Everytime there is "Daten: " I want to grab the postal and city from it and create a new txt file which should look like this:

18472 Berlin
52621 Frankfurt
72223 Bonn
......

Looking at my past Q&A it is obvious that my knowledge is in web based technologies. I'd appreciate any help

edit: postal and city are not always at the same "location", because sometimes there is an additional entry between street and postalcode/city. Example:

Susimega*hfu827aaa
Daten: Susi Lanzwelt<br />Mondstr. 16<br />bei Muellers<br />48812 Magdeburg<br />Deutschland

Upvotes: 0

Views: 68

Answers (1)

Stephan
Stephan

Reputation: 56180

easier than you seem to think:

for /f "tokens=5 delims=<>" %%a in (test.txt) do echo %%a

If you're going to replace <br /> with a comma, use "tokens=3 delims=,"

(use %a instead of %%a if you use it on command line)

to process the additional entry:

(for /f "tokens=5,7 delims=<>" %%a in (t.txt) do (
  echo %%a|findstr /b "[0-9]">nul && echo %%a || echo %%b
)>output.txt

the trick: if token 5 starts with a number then echo token 5 else echo token 7

Upvotes: 2

Related Questions