Solved

Batch File: Parse data from text file

Posted on 2011-03-25
5
353 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 52

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 52

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This is about my first experience with programming Arduino.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

895 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

16 Experts available now in Live!

Get 1:1 Help Now