Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Batch File: Parse data from text file

Posted on 2011-03-25
5
Medium Priority
?
385 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 71

Accepted Solution

by:
Qlemo earned 1800 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 57

Assisted Solution

by:Bill Prew
Bill Prew earned 200 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 57

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Make the most of your online learning experience.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Introduction to Processes

670 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