Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This site is awesome!...Things I have been trying to figure out for weeks, I got the answer in hours!..."

Geography

Where in the world do Tek-Tips members come from?

Batch File copying text but cuts off text at the first spaceHelpful Member! 

bmacbmac (IS/IT--Management)
19 Jul 12 16:24
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 
Helpful Member!  tootiredtocare (TechnicalUser)
19 Jul 12 18:01
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 ( 

bmacbmac (IS/IT--Management)
21 Jul 12 16:22
That was it! Thanks!

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close