Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch File copying text but cuts off text at the first space 1

Status
Not open for further replies.

bmacbmac

IS-IT--Management
Jan 26, 2006
392
0
0
US
Hi. I have a batch file to remove the last line of my .txt file. In this case it copies all rows (except the last one) from d177920101id.txt
and into docinfo.txt

It copies the lines great, but each line is cut off at the first space.

So in d177920101id.txt I have the lines
BIG|CONSTRUCTION|INC
HANSEN|TOWING AND REPAIR|INC
EOF 2

In docinfo.txt I end up with
BIG|CONSTRUCTION|INC
HANSEN|TOWING

Any idea how I can change my batch file to copy the entire lines including the spaces?

Code:
SETLOCAL ENABLEDELAYEDEXPANSION

rem Count the lines in file
set /a count=-1
for /F %%a in (d177920101id.txt) DO set /a count=!count!+1

rem Create empty temp file
copy /y NUL tempfile.txt >NUL

rem Copy all but last line
for /F %%a in (d177920101id.txt) DO (
IF /I !count! GTR 0 (
echo %%a >> tempfile.txt
set /a count=!count!-1
)
)

rem overwrite original file, delete temp file
copy /y tempfile.txt docinfo.txt >NUL
del tempfile.txt
 
In your for statement, you have nothing to identify what the delimiter is, so when it hits the space, it assumes it's the end of the line

I think the following adjustment will help. Replace this line
Code:
for /F %%a in (d177920101id.txt) DO (

with this
Code:
for /F "delims=" %%a in (d177920101id.txt) DO (

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top