Solved How to Append text to Text File with no new Line using CMD

September 17, 2013 at 23:34:38
Specs: Windows 7
Hi, Am trying to append value to a property file "echo content >>filename"
its appending content as a new line. But i wish to append the "content" on the same line.Please, help me on this.

Ex : Original txt file content


But want to append like

hi hello

See More: How to Append text to Text File with no new Line using CMD

Report •

September 18, 2013 at 09:58:57
✔ Best Answer

setlocal EnableDelayedExpansion
set "line="
for /f "delims=" %%a in (myfile.txt) do (
  set "line=!line!%%a"
>newmyfile.txt echo !text!

please test, works for the above case


Report •

September 19, 2013 at 00:59:22
::====== script starts here ===============
:: conn2.bat 2013-09-19 14:45:15.98
@echo off > NEWFILE & setLocal enableDELAYedeXpansioN

set N=
call :sub1 myfile

set X=
for /f "tokens=* delims= " %%a in (myfile) do (
set/a X+=1
if !N! equ !X! (
echo %%a hello
) else (
echo %%a
goto :eof

for /f "tokens=* delims= " %%i in (%1) do (
set /a N+=1
goto :eof
::====== script ends here =================

M2 Golden-Triangle

Report •

September 19, 2013 at 18:59:16
Your problem is not exactly clear to me, due to discrepancies between your stated problem and the example, so I will try a shotgun approach. If you want to append to a file without a trailing CRLF, this might do:
::======== append.bat: no CRLF at EOF
set app= this text will be appended without linefeed...
set /p=%app%<nul>>file.txt
set app=more data on same line
set /p=%app%<nul>>file.txt
::======== end batchscript

If you want to remove the final CRLF from a file, it's slightly more involved:
::======== begin batchscript LASTCRLF
@echo off>newfile & setlocal
set appended=NO-one here but us linefeeds
for /f "tokens=1 delims=[]" %%a in ('find /n /v ""^<%1') do set linecnt=%%a
for /f "tokens=1* delims=[]" %%a in ('find /v /n ""^<%1') do (
if "%%a" neq "%linecnt%" (
>>newfile echo %%b
) else (
>>newfile echo %%b %appended%
move newfile %1
::======= end batchscript
subject, of course, to the limitations of batch and esp. ECHO with certain system characters.

Report •

Related Solutions

September 20, 2013 at 09:51:45

That's what I did; without FIND.

M2 Golden-Triangle

Report •

Ask Question