Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Batch file to filter data

1 view
Skip to first unread message

FD

unread,
May 7, 2002, 7:43:56 AM5/7/02
to
Hello,

I have a log-file with al lot af data and I wan't to make it more readable.
How can I make a batchfile to search aunique code (mac adress in my case)
and take this line + the 10 lines after the unique code to send to a new
file with >> newlogfile.log.

Can someone help?

Freddy


Dr John Stockton

unread,
May 7, 2002, 3:05:50 PM5/7/02
to
JRS: In article <3cd7becf$0$235$4d4e...@read.news.nl.uu.net>, seen in
news:alt.msdos.batch, FD <f.d...@sze.nl> posted at Tue, 7 May 2002
13:43:56 :-

>
>I have a log-file with al lot af data and I wan't to make it more readable.
>How can I make a batchfile to search aunique code (mac adress in my case)
>and take this line + the 10 lines after the unique code to send to a new
>file with >> newlogfile.log.
>

You have posted to a newsgroup which should not deal with NT and also to
one which should only deal with NT and to a third.

In DOS..Win98, and probably also in NT, you can use MiniTrue (and
perhaps SED) :

C:\HOMEPAGE\PROGRAMS>mtr -x+ -o nowminus.txt - "Time\.(.*\r\n){10}"
Summer Time. References to JD & MJD really mean CJD & CMJD.

One day, I may introduce NOW_PLUS and develop that instead. In it, the
options S M H D W N Y will be reversed in effect, and there will be one
set of numbers for Formatting Date and another for Time (and separate
for Zeroing?).

For examples of the use of NOWMINUS, see below.

C:\HOMEPAGE\PROGRAMS>


The line containing "Time." and another 9 lines have been sent to Std.
Out; you should find the adjustments for your case easy enough. I have
manually added a tab to the start of each output line; each should arrive
as 8 spaces.

--
© John Stockton, Surrey, UK. j...@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
I find MiniTrue useful for viewing/searching/altering files, at a DOS prompt;
free, DOS/UNIX, from <URL:http://www.pagesz.net/~minitrue/> & Garbo fileutil

Todd Vargo

unread,
May 7, 2002, 7:39:11 PM5/7/02
to

"FD" <f.d...@sze.nl> wrote in message
news:3cd7becf$0$235$4d4e...@read.news.nl.uu.net...

Try this batch...

:: This batch requires Windows Script Host v5.6
:: Written by Todd Vargo in Windows 98 on May 07, 2002
@echo off
if GOTO:==%1 %1%2 (Subroutine Handler)
%comspec% /c %0 GOTO: MakeVBS Echo.>$.VBS
type log-file |cscript //nologo $.vbs >newlogfile.log
del $.vbs
goto end
::
:MakeVBS
%3 Search = "Put string to find here."
%3 On Error Resume Next
%3 Do While Not WScript.StdIn.AtEndOfStream
%3 str = WScript.StdIn.ReadLine
%3 ret = Instr(str, search)
%3 If not ret = 0 Then
%3 WScript.StdOut.WriteLine str
%3 For Count = 1 To 10
%3 str = WScript.StdIn.ReadLine
%3 WScript.StdOut.WriteLine str
%3 Next
%3 Exit Do
%3 End If
%3 Loop
:end
::

--
Todd Vargo (body of message must contain my name to reply by email)

laura fairhead

unread,
May 8, 2002, 5:52:46 PM5/8/02
to

'sed' would give you a reasonably easy solution, if you are just
after the 1st match and the 10 lines after that the 'n' command
could be used to get them and then 'q' to quit;

SED "/mac_address/{n;n;n;n;n;n;n;n;n;n;q;};d" FILENAME >NEWLOGFILE.LOG

If you want to get every match and the 10 lines after them and
allow for overlapping (ie; still keep checking in the 10 subsequent
lines for a match and reset the counter if one is found) a counter
could be kept in the hold space of how many lines to print out;

SED -n "/mac_address/{x;s/.*/-----------/;x;};x;/-/{s/-//;x;p;x;};x" FILENAME >NEWLOGFILE.LOG

A compact version of 'sed' can be downloaded here;

ftp://garbo.uwasa.fi/pc/unix/sed15x.zip


>Freddy
>
>

byefrom

--
laura fairhead # la...@madonnaweb.com http://lf.8k.com
# if you are bored crack my sig.
1F8B0808CABB793C0000666667002D8E410E83300C04EF91F2877D00CA138A7A
EAA98F30C494480157B623C4EF1B508FDED1CEFA9152A23DE35D661593C5318E
630C313CD701BE92E390563326EE17A3CA818F5266E4C2461547F1F5267659CA
8EE2092F76C329ED02CA430C5373CC62FF94BAC6210B36D9F9BC4AB53378D978
80F2978A1A6E5D6F5133B67B6113178DC1059526698AFE5C17A5187E7D930492

0 new messages