how to use batch file to modify text file(aka system commands in c++)
so, I am creating a text kind of system just for fun. I have created a program(I'm using c++, but system commands so it is somewhat same as batch just stored in .exe and variables are easier for me as I'm more used to c++ enviroment. so I have created program that reads specific txt file, and refreshes constantly. For the 2nd program I planned to write things down to that .txt. Now, here is my problem. to write down I'm using echo command as echo [variable] > file.txt, but the problem is it deletes earlier content of the file. I would like it to create new line and write it there, and still keep the old ones? thanks in advance
< >
Showing 1-9 of 9 comments
Omega Nov 4, 2017 @ 2:39pm 
I am not that great with .bat scripts so I will just link you some of the first search results in Google. :P

https://stackoverflow.com/questions/1115508/batch-find-and-edit-lines-in-txt-file

https://stackoverflow.com/questions/23574631/edit-text-file-using-batch-file
Sila Drenja Nov 4, 2017 @ 2:58pm 
Those are to replace certain text or line. I need to insert
Sila Drenja Nov 4, 2017 @ 2:59pm 
I googled it too. Haha read few more pages and all to replace as I managed to find. Btw, are you the same person that was answering my dos vm post?
Omega Nov 4, 2017 @ 3:00pm 
Yep :P
Sila Drenja Nov 4, 2017 @ 3:14pm 
Hahaha thx alot
vadim Nov 4, 2017 @ 3:43pm 
That's why i prefer Unix-like OSes. They have utilities like sed which intented to do what OP wants.
> replaces the contents of a file.
>> appends content to a file.
I assume that Windows works similar to various scripting languages and other operating systems. So maybe you simply need to use ">>" instead of ">" to pipe output to the end of a file instead of replacing the file.

I have not actually written any compiled C related PC programs from scratch, but have written various scripts for CGI (dynamic web server content) which got me into Linux over 20 years ago when my ISP gave us web space on apache webserver in SunOS, and it was easier to simply generate and test content (and CGI scripts) in Linux and simply upload them, than to do that in Windows and have to convert paths and some modules. I did some assembly language programming, but that was early to mid-1980's on an Apple ][+ somewhat out of necessity to do what I wanted to do with a primative computer. And I wrote some assembly programs for MS-DOS which grew much bigger in file size when converted to Windows.
Last edited by MaddDoktor [Linux]; Nov 4, 2017 @ 4:25pm
RGX12 Nov 4, 2017 @ 5:18pm 
It's very simple. As MaddDoktor said, a single redirect symbol (>) overwrites the previous file content, if any, and a double redirect (>>) appends to existing file content. So you'd have something like,
ECHO %some_variable% >> myfile.txt
Sila Drenja Nov 4, 2017 @ 5:29pm 
Originally posted by MaddDoktor Linux:
> replaces the contents of a file.
>> appends content to a file.
I assume that Windows works similar to various scripting languages and other operating systems. So maybe you simply need to use ">>" instead of ">" to pipe output to the end of a file instead of replacing the file.

I have not actually written any compiled C related PC programs from scratch, but have written various scripts for CGI (dynamic web server content) which got me into Linux over 20 years ago when my ISP gave us web space on apache webserver in SunOS, and it was easier to simply generate and test content (and CGI scripts) in Linux and simply upload them, than to do that in Windows and have to convert paths and some modules. I did some assembly language programming, but that was early to mid-1980's on an Apple ][+ somewhat out of necessity to do what I wanted to do with a primative computer. And I wrote some assembly programs for MS-DOS which grew much bigger in file size when converted to Windows. [/quote]


Originally posted by RGX12:
It's very simple. As MaddDoktor said, a single redirect symbol (>) overwrites the previous file content, if any, and a double redirect (>>) appends to existing file content. So you'd have something like,
ECHO %some_variable% >> myfile.txt
Thank you alot
< >
Showing 1-9 of 9 comments
Per page: 1530 50

Date Posted: Nov 4, 2017 @ 2:36pm
Posts: 9