Solved

Batch File: Parse data from text file

Posted on 2011-03-25
5
367 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 69

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 54

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 54

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb example issues 3 47
Rename all files in a directory to numerical order 26 31
PowerShell logging 1 27
powershell automatic variable for results 21 14
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

685 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