Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I've got a log that has to be reformatted in a better readable format. I can extract the ip properly, but not the port. Maybe you guys can help me.example code:
10.0.0.2,"","OK","ServerName;H1313308;InstanceName;MSSQLSERVER;IsClu stered;No;Version;8.00.194;np;\\H1313308\pipe\sql\ query;tcp;4133;;"
10.0.0.3,"","OK","ServerName;PROWIN03;InstanceName;MSSQLSERVER;IsClu stered;No;Version;8.00.194;tcp;1433;np;\\PROWIN03\ pipe\\sql\query;;"
10.0.0.4,"","OK","ServerName;PROWIN07;InstanceName;MSSQLSERVER;IsClu stered;No;Version;8.00.194;tcp;1433;np;\\PROWIN07\ pipe\\sql\query;;"
10.0.0.9,"","OK","ServerName;PROWINDEV;InstanceName;MSSQLSERVER;IsCl ustered;No;Version;8.00.194;tcp;1433;np;\\PROWINDE V\pipe\\sql\query;;"
10.0.0.10,"","OK","ServerName;VDS-238462;InstanceName;MSSQLSERVER;IsClustered;No;Ver sion;8.00.194;tcp;1433;np;\\VDS-238462\pipe\\sql\query;;"The correct format has to be:
ip:port
example from the first line:
10.0.0.2:4133
Thx in advance

Here a Windows XP/2K batch script
:: EDLOG.BAT Usage: EDLOG Log_File > Edited_Log
@echo off & setlocal EnableDelayedExpansion
for /F "tokens=1* delims=," %%a in ('type "%*"') do (
set ip=%%a
set port=%%b
set port=!port:*tcp;=!
set port=!port:"=!
for /F "tokens=1 delims=;" %%j in ("!port!") do set port=%%j
echo.!ip!:!port!
)
:: End_Of_BatchNext time post your operating system.

Here's a Perl command.
===========================================
perl -ne "if(/^([\d.]+).*tcp;(\d+)/){print qq($1:$2\n)}" file.log

@FishMonger,
I hope the OP will appreciate your or my solution as I noticed more and more people post a question, let regulars work out the problem and then disappear.
Anyway I appreciate your code, terse and cool as usual.

IVO,
Thanks for the appreciation.
I've noticed over the last few months that there has been a shift in the type of programming questions. It seams that the vast majority of them are for batch scripts. I'm often amazed at some of the batch scripts you several others provide, but I just can't set aside Perl, so I'll keep plugging it. :o)

if you can download gawk for windows here:
http://gnuwin32.sourceforge.net/pac...save the below script as script.awk
BEGIN { FS="[,;]"}
{
printf $1":"
for(i=1;i<=NF;i++) { if ( $i=="tcp" ) print $(i+1) }
}
on command line:
c:\test> gawk -f script.awk file

It's not often you aee somebody using /
Does that run on RISC?
LOL
=====================================
If at first you don't succeed, you're about average.M2

Thanks a lot everyone. I didn't expect all those replies.
I appreciate it. I love this forum. :p

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |