Extract lines from input file, help please...

April 27, 2010 at 01:23:47
Specs: Windows Vista
Hi,

I am trying to get second and third last line from an input file, do you guys have any idea how to do it?


56,801 C:\cygwin
77,329 C:\SmartSound Software
117,149 C:\confluence
214,604 C:\ManageEngine
226,104 C:\NVIDIA
540,555 C:\MSOCache
2,260,573 C:\ProgramData
9,613,320 C:\Users
21,471,843 C:\Windows
23,182,847 C:\Program Files
62,313,071 C:\

I am trying to extract the "C:\Program Files
" and "C:\Windows", any idea how to achieve this?

Thanks alot guys


See More: Extract lines from input file, help please...

Report •

#1
April 27, 2010 at 04:09:12
@echo off > newfile & setLocal enableDELAYedeXpansion

set N=
for /f "tokens=* delims= " %%a in (thefile) do (
set /a N+=1
)

set /a S=N-1
set /a T=N-2

set N=
for /f "tokens=* delims= " %%a in (thefile) do (
set /a N+=1
if !N! equ !T! >> newfile echo.%%a
if !N! equ !S! >> newfile echo.%%a
)


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

M2


Report •

#2
April 27, 2010 at 05:04:19
Hi M2,

Thanks for the reply, but the result of your script is :
21,471,843 C:\Windows
23,182,847 C:\Program Files

what I need is :
C:\Windows
C:\Program Files

The problem is generate the "C:\Program Files" because there is the space in between, I can only be able to generate "C:\Program".

Do you mind to give further resolution?

Thanks man


Report •

#3
April 27, 2010 at 05:32:49
I don't mind.

In the future note that Vista/Nt has nothing to do with DOS. This belongs either in the Vista or the programming forum.

====================================
@echo off > newfile & setLocal enableDELAYedeXpansion

set N=
for /f "tokens=* delims= " %%a in (thefile) do (
set /a N+=1
)

set /a S=N-1
set /a T=N-2

set N=
for /f "tokens=1* delims= " %%a in (thefile) do (
set /a N+=1
if !N! equ !T! >> newfile echo.%%b
if !N! equ !S! >> newfile echo.%%b
)


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

M2


Report •

Related Solutions

#4
April 27, 2010 at 05:57:07
Thank you very much M2, yes I will remember to go to other forum.

One last question : what is the setLocal enableDELAYedeXpansion for?

Cheers,


Report •

#5
April 27, 2010 at 06:01:46
help setLocal enableDELAYedeXpansion


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

M2


Report •

#6
April 27, 2010 at 06:07:39
Ok,

so why didnt you put endlocal at the end of the script?


Report •

#7
April 27, 2010 at 06:21:20
In most cases it ends when the bat quits.

There is probably a situation in which this doesn't work. Just waiting to bite my butt.


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

M2


Report •

Ask Question