Suppress new line

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
iny1111
Posts: 4
Joined: Thu Jul 15, 2010 6:56 pm

Suppress new line

Post by iny1111 » Wed Jul 20, 2011 12:46 am

Hello, I have a little problem with one bat file:FOR /F "tokens=1 delims=" %%G IN (c:file1.txt) DO (set str=%%G)echo %str% > c:file2.txtIn file1.txt there is only one word. For example WORD1. Without any other empty character or blank line.When I launch above .bat file, it saved me WORD1 into file2, but with additional space character + blank line.Why this always occured ? Why it put me always additional blank character and new line into file2.txt ? How to avoid this ?

jvierra
Posts: 13907
Joined: Tue May 22, 2007 9:57 am
Contact:

Suppress new line

Post by jvierra » Wed Jul 20, 2011 2:54 am

This will get rid of teh space. The line feed you are stuck with.

FOR /F "tokens=1" %%G IN (file1.txt) DO (set str=%%G)(echo.%str%)>file2.txt

To get rid of the newline jsut concatenate all output and write at the end one time.
jvierra2011-07-20 09:57:36

jvierra
Posts: 13907
Joined: Tue May 22, 2007 9:57 am
Contact:

Suppress new line

Post by jvierra » Fri Aug 19, 2011 4:38 am

FOR /F "tokens=1 delims=" %%G IN (c:file1.txt) DO (set str=%%G)set /p =%str%<nul >c:file2.txt> c:file3.txt echo %str%


What does the third line do?

Locked