Computing.Net > Forums > Programming > Extact info from lines containing x text

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.

Extact info from lines containing x text

Reply to Message Icon

Name: gduncan229
Date: October 17, 2009 at 06:28:31 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

Honestly I'm new to programming, and I'm needing some help with something I'm working on. And honestly the files I'm grabbing from isn't helping me.
The first problem is information I'm trying to extract from the log files needs to be extracted from the bottom up and stop looking at say the word stop.
Secondly some of the log files have more than one instance of the information and it needs to be processed seperately, and then the file needs to be saved with the day before's date.
so the info goes kinda like this
245.04,756.23,test
345.74.123.87,test2
123.99,123.56,test3
I'm looking to extract the information from the second group of numbers, and the problem is sometimes the test2 line might not be there. So I want to get a value of 0 put if it's not there.
Any help would be greatly appreciated.



Sponsored Link
Ads by Google

Response Number 1
Name: wizard-fred
Date: October 17, 2009 at 08:58:01 Pacific
Reply:

Reverse sort the file or load in a database so it can be scanned line by line from rear.


0

Response Number 2
Name: Mechanix2Go
Date: October 17, 2009 at 11:23:47 Pacific
Reply:

You need to be clear about the rules for extraction.


=====================================
Helping others achieve escape felicity

M2


0

Response Number 3
Name: gduncan229
Date: October 17, 2009 at 11:41:16 Pacific
Reply:

Sorry that I forgot a couple of important parts
This is off a text file that I can't really alter.

The rules of extraction would be basically be.

245.04,756.23,test
345.74.123.87,test2
123.99,123.56,test4

Look for test, test2, test3, test4 extract data. If data for anything looked for isn't present enter 0 so that extracted would come out like
756.23
123.87
0
123.56

Thank you


0

Response Number 4
Name: Mechanix2Go
Date: October 17, 2009 at 19:29:52 Pacific
Reply:

@echo off > newfile & setLocal enableDELAYedexpansion

set N=

for /f "tokens=* delims= " %%a in (datafile) do (
set /a N+=1
if !N! equ 1 (
> mydata echo %%a1
) else (
>> mydata echo %%a
)
)

set N=
set X=

for /f "tokens=3 delims=," %%a in (mydata) do (
set str=%%a
set X=!str:test=!
)

for /L %%i in (1 1 !X!) do (
set /a N+=1
set data=0
for /f "tokens=2-3 delims=," %%d in (mydata) do (
if %%e equ test!N! (
set data=%%d
)
)
>> newfile echo !data!
)


=====================================
Helping others achieve escape felicity

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Help with VB macros Backup Only Modified or N...


Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Extact info from lines containing x text

deleting multiple lines in multiple text file www.computing.net/answers/programming/deleting-multiple-lines-in-multiple-text-file/19862.html

Delete Last line of a text file www.computing.net/answers/programming/delete-last-line-of-a-text-file/20179.html

Batch file to extract lines of text from .ini www.computing.net/answers/programming/batch-file-to-extract-lines-of-text-from-ini/19089.html