Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

Batch File: Parse data from text file

Hi there,

I need to parse data from a text file and output it in a file.

Columns are defined as follows:
No; Protocol;Timeout;Source Address;Remote Address;Service Name;State

The expected output for the first line would be:
1;TCP;320;192.168.1.161;70.40.255.122;4876;ESTABLISHED

Thanks for your help,
Rene

 
@ECHO OFF

SETLOCAL enabledelayedexpansion

IF EXIST Connections.log DEL Connections.log

FOR /F "tokens=1-7 delims=<>" %%A IN (Connections.TXT) DO ECHO %%A;%%B;%%C;%%D;%%E;%%F;%%G >>Connections.log

Open in new window

<td align="right">1</td><td>TCP</td><td align="right">320</td><td align="right"><a title="Geotool" href="javascript:openGeotool('192.168.1.161')">192.168.1.161</a></td><td align="right"><a title="Geotool" href="javascript:openGeotool('70.40.255.122')">70.40.255.122</a></td><td align="right">4876</td><td>ESTABLISHED</td>
</tr>
<tr>
<td align="right">2</td><td>TCP</td><td align="right">449</td><td align="right"><a title="Geotool" href="javascript:openGeotool('192.168.1.103')">192.168.1.103</a></td><td align="right"><a title="Geotool" href="javascript:openGeotool('208.29.69.176')">208.29.69.176</a></td><td align="right">1180</td><td>ESTABLISHED</td>
</tr>
<tr>
<td align="right">3</td><td>TCP</td><td align="right">366</td><td align="right"><a title="Geotool" href="javascript:openGeotool('192.168.1.103')">192.168.1.103</a></td><td align="right"><a title="Geotool" href="javascript:openGeotool('60.69.197.8')">60.69.197.8</a></td><td align="right">170</td><td>ESTABLISHED</td>
</tr>
<tr>
<td align="right">4</td><td>TCP</td><td align="right">414</td><td align="right"><a title="Geotool" href="javascript:openGeotool('70.40.255.122')">70.40.255.122</a></td><td align="right"><a title="Geotool" href="javascript:openGeotool('50.54.198.124')">50.54.198.124</a></td><td align="right">13444</td><td>ESTABLISHED</td>
</tr>
<tr>
<td align="right">5</td><td>TCP</td><td align="right">941</td><td align="right"><a title="Geotool" href="javascript:openGeotool('192.168.1.103')">192.168.1.103</a></td><td align="right"><a title="Geotool" href="javascript:openGeotool('98.6.120.33')">98.6.120.33</a></td><td align="right">170</td><td>ESTABLISHED</td>

Open in new window


0
ReneGe
Asked:
ReneGe
  • 2
  • 2
2 Solutions
 
QlemoC++ DeveloperCommented:
@ECHO OFF
(FOR /F "tokens=2,5,8,12,17,21,24 delims=<>" %%A IN (Connections.TXT) DO ECHO %%A;%%B;%%C;%%D;%%E;%%F;%%G) >Connections.log

Open in new window

should do that.
0
 
Bill PrewCommented:
Same token list I came up with Qlemo, glad I refreshed before duplicating your post.

~bp
0
 
ReneGeAuthor Commented:
The command line works like a charm.

Thanks a million times!!

Cheers,
Rene
0
 
Bill PrewCommented:
That wasn't necessary Rene (I owe you 50 Clemo) but thanks for the friendly assist.

~bp
0
 
ReneGeAuthor Commented:
With all the help you provided me with, I owe you both a lot more than 50 points.

Thanks again and lot of cheers,
Rene
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now