Overwrite an existing file(s)

June 29, 2009 at 13:45:22
Specs: Windows XP
I have 2 files in a say c:\input\ldap.
File names are
L1_CC_yyyymmdd.txt
L1_DD_yyyymmdd.txt


I need to remove some lines from both of these files and save it and copy to c:\output\ldap.

@echo off & setLocal enableDELAYedexpansion

:main
for /f "tokens=* delims= " %%a in ('dir/b *.txt') do (
echo %%a


:count lines; set T & R
for /f "tokens=* delims= " %%d in ('find /v /c "" ^< %%a') do (
set T=%%d
set /a R=!T!-2
)
--
-- some code here that would call :noFIRST
:chopLAST

:noFIRST
::== noFIRST.bat
@echo off > NewLDAP1.txt


set FIRST=Y
echo !Input!
for /f "tokens=* delims= " %%a in ('dir/b *.txt') do (
for /f "tokens=*" %%L in (%%a) do call :1 %%L
goto :eof

:1
if %FIRST%==N echo %*>>NewLDAP1.txt
set FIRST=N
)
goto :eof


:chopLAST
::==chopLAST.bat

find /v "" NewLDAP1.txt > ~Temp.txt
for /f "tokens=1,* delims=[]" %%a in (~Temp.txt) do set Last=%%a
type NewLDAP1.txt | find /v "%Last%" >> NewLDAP2.txt

/**********************************************
==> don't know how to read the 1st file so again I am dir/b LDAP*.txt.
**********************************************/

for /f "tokens=* delims= " %%a in ('dir/b LDAP*.txt') do (
move/y NewLDAP2.txt %%a
)

del New*.txt
del ~Temp.txt

move *.txt c:\output\ldap.

It does not read the second file at all. What do I need to change in call :chopLast?? Please read above comments.

Ok, so trying to copy NewLDAP2.txt to L1_CC_yyyymmdd.txt and then delete NewLDAP2.txt and move the L1_CC* to /output/ldap.

Then again copy NewLDAP2.txt to L1_DD_yyyymmdd.txt and then delete NewLDAP2.txt and move the L1_DD* to /output/ldap.

Hope this makes sense.


See More: Overwrite an existing file(s)

Report •


#1
June 29, 2009 at 15:55:59
This should be posted in the "Programming" forum. The link is on the right hand side of this page.

http://ewen.uuuq.com/


Report •
Related Solutions


Ask Question