Computing.Net > Forums > Programming > reformat log file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

reformat log file

Reply to Message Icon

Name: MaRtO
Date: June 27, 2008 at 11:18:38 Pacific
OS: /
CPU/Ram: /
Product: /
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: FishMonger
Date: June 27, 2008 at 12:54:13 Pacific
Reply:

Which scripting language do you want to use?


0

Response Number 2
Name: IVO
Date: June 27, 2008 at 13:08:53 Pacific
Reply:

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_Batch

Next time post your operating system.


0

Response Number 3
Name: FishMonger
Date: June 27, 2008 at 14:01:39 Pacific
Reply:

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


0

Response Number 4
Name: IVO
Date: June 27, 2008 at 14:11:19 Pacific
Reply:

@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.


0

Response Number 5
Name: FishMonger
Date: June 27, 2008 at 14:40:42 Pacific
Reply:

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)


0

Related Posts

See More



Response Number 6
Name: ghostdog
Date: June 27, 2008 at 23:55:29 Pacific
Reply:

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


0

Response Number 7
Name: Mechanix2Go
Date: June 28, 2008 at 00:33:36 Pacific
Reply:

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


0

Response Number 8
Name: MaRtO
Date: June 28, 2008 at 01:08:20 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: reformat log file

Create log file www.computing.net/answers/programming/create-log-file-/15402.html

write test line into log file with www.computing.net/answers/programming/write-test-line-into-log-file-with-/15272.html

qbasic zip log files program help www.computing.net/answers/programming/qbasic-zip-log-files-program-help/12511.html