Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Subject: Filter text files!

Original Message
Name: QZero
Date: May 1, 2008 at 19:31:28 Pacific
Subject: Filter text files!
OS: WinXP
CPU/Ram: 2GB
Model/Manufacturer: IBM server
Comment:
Hi All,

I need to collect some logs everyday and I am try to write a DOS batch program to do it. But since I am new to the DOS command, can everyone please help!

The log file contain like this :
[blankline]
[2008.03.02-20.00.23 kfdakjklefsfda] 123456
[blankline]
[2008.03.02-20.10.23 kfdakjklefsfda] 232645
[blankline]
[2008.03.02-20.00.23 kfdakjklefsfda] date
[2008.03.02-20.04.03 kfdakjklefsfda] time
[2008.03.02-20.56.13 kfdakjklefsfda] set
[2008.03.02-20.44.03 kfdakjklefsfda] info
[blankline]

What I really like to collect is the last part, between the last third blankline and the last second blankline!
The output I expect is:

date
time
set
info

Thanks for any kind of advice!

Learning a bit everyday!


Report Offensive Message For Removal

Response Number 1
Name: Mechanix2Go
Date: May 1, 2008 at 21:25:43 Pacific
Subject: Filter text files!
Reply: (edit)
Do you want just this:

date
time
set
info

or these 4 lines:

[2008.03.02-20.00.23 kfdakjklefsfda] date
[2008.03.02-20.04.03 kfdakjklefsfda] time
[2008.03.02-20.56.13 kfdakjklefsfda] set
[2008.03.02-20.44.03 kfdakjklefsfda] info


=====================================
If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 2
Name: ghostdog
Date: May 2, 2008 at 05:47:09 Pacific
Subject: Filter text files!
Reply: (edit)
if you can download gawk from here:http://gnuwin32.sourceforge.net/packages/gawk.htm


BEGIN{RS=""}{ last=$0}
END{
for ( i=1;i<=NF;i++) {
if ( $i !~ /\[|\]/ ) {
print $i
}
}
}

save the above as script.awk and on command line

c:\test> gawk -f script.awk file


Report Offensive Follow Up For Removal

Response Number 3
Name: Mechanix2Go
Date: May 2, 2008 at 06:39:55 Pacific
Subject: Filter text files!
Reply: (edit)
To get those 4 lines with bat:

::=========================
@echo off > newfile
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (log) do (
set /a N+=1
for /L %%d in (6 1 9) do (
if !N! equ %%d echo %%a >> newfile
)
)


=====================================
If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 4
Name: QZero
Date: May 4, 2008 at 19:42:24 Pacific
Subject: Filter text files!
Reply: (edit)
Hi Mechanix2Go,

Thanks for your help!
But I guess I do not ask the question right :-( Since the log file might have a lot of line, some time 20, sometime more than 100!

The script you write is set to output the line form line 6 to 9! It is not always ture for my case!

I am more thinking like find the last second blankline and start to export until it meet the last blankline!

blankline]
[2008.03.02-20.00.23 kfdakjklefsfda] 123456
[blankline]
[2008.03.02-20.10.23 kfdakjklefsfda] 232645
.
.
.
[blankline] <-----find the line number:x
[2008.03.02-20.00.23 kfdakjklefsfda] date
[2008.03.02-20.04.03 kfdakjklefsfda] time
[2008.03.02-20.56.13 kfdakjklefsfda] set
[2008.03.02-20.44.03 kfdakjklefsfda] info
[blankline] <-----find the last line:y

export the lines form x to y

But not sure how to write this part! ;-(

Learning a bit everyday!


Report Offensive Follow Up For Removal

Response Number 5
Name: Mechanix2Go
Date: May 5, 2008 at 02:39:19 Pacific
Subject: Filter text files!
Reply: (edit)
Fist, having the 'last line' blank is usually irrelavent.

Next, do you need the lines 'after the last blank line'?

Or what?


=====================================
If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 6
Name: QZero
Date: May 5, 2008 at 17:46:50 Pacific
Subject: Filter text files!
Reply: (edit)
Well, the log file always end with a blank line!

Thanks

Learning a bit everyday!


Report Offensive Follow Up For Removal

Response Number 7
Name: QZero
Date: May 7, 2008 at 08:15:48 Pacific
Subject: Filter text files!
Reply: (edit)
M2,

I get a problem to run the script, it only export one line...the sixth line!
And I add a line inside the for loop so it will echo the vaule of N; however, the %N% always show 0! any idea??

Learning a bit everyday!


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Filter text files!

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software



Version Tracker Pro
Keep your software current and secure, effortlessly

Click Here for a Free Scan

Driver Agent
Automatically find the latest drivers for your computer.
Click Here for a Free Scan



The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC