Solved

Batch File: Parse data from text file

Posted on 2011-03-25
5
347 Views
Last Modified: 2012-05-11
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
Comment
Question by:ReneGe
  • 2
  • 2
5 Comments
 
LVL 68

Accepted Solution

by:
Qlemo earned 450 total points
ID: 35217577
@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
 
LVL 51

Assisted Solution

by:Bill Prew
Bill Prew earned 50 total points
ID: 35217787
Same token list I came up with Qlemo, glad I refreshed before duplicating your post.

~bp
0
 
LVL 10

Author Comment

by:ReneGe
ID: 35218003
The command line works like a charm.

Thanks a million times!!

Cheers,
Rene
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 35218107
That wasn't necessary Rene (I owe you 50 Clemo) but thanks for the friendly assist.

~bp
0
 
LVL 10

Author Comment

by:ReneGe
ID: 35218183
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now