0

I made this batch file to write in a text file:

rem Saved in E:\Downloads\dat\currentstate.bat
@echo off
@echo Current State> currentstate.txt
@echo League>> currentstate.txt

So the output right now in the txt is:

Current State
League

1st batch file: How can I make a batch file in order to add the word "camera" after the last line of any txt file. I would like to run the new batch file and my output to be:

Current State
League
Camera

2nd batch file: How can I make a batch file this time to replace everything in the first line of any txt file (in my example it happens to be "Current State") with the word "workbook" so the output to be:

workbook
League
Camera

I searched a lot in the forum/web but i couldn't find answers to my questions. Sorry for the double questioning and thanks in advance.

kavamarou
  • 1
  • 3
  • http://stackoverflow.com/questions/60034/how-can-you-find-and-replace-text-in-a-file-using-the-windows-command-line-envir – Balaji Reddy Oct 13 '16 at 21:06
  • 2
    You have not provided any code relevant to your question and there are two questions, which I think it technically an abuse of this site. The questions appear more like you have been tasked with an assignment and hoping someone else will do that for you. Please see the [tour] and learn [ask]. – Compo Oct 13 '16 at 21:10
  • Balaji I read carefully this article but i am not sure it is what i search. I want to edit a txt file using its lines and not to edit/work on other specific words in it. In addition i would like not to use powershell – kavamarou Oct 13 '16 at 21:15
  • Concerning the first part of your question: are you seriously asking how to append a line, although you are already doing that in your code?? – aschipfl Oct 14 '16 at 11:52
  • Concerning the secod part: you will need a temporary file; do `echo workbook> "currentstate.tmp"` first, then do `more +1 "currentstate.txt" >> "currentstate.tmp"`; finally do `move /Y "currentstate.tmp" "currentstate.txt"`... – aschipfl Oct 14 '16 at 11:59
  • Thanks a lot, aschipfl, for your help. Your code combination worked like a charm in my third batch. As for your first concerning I really have to run a separate batch file to append a line after my initial code (if someone could help me with that I would apreciate that). – kavamarou Oct 14 '16 at 21:37
  • @kavamarou: `>>` [appends to a file](https://ss64.com/nt/syntax-redirection.html). So just `echo Camera>>currentstate.txt` does what you want. You are already using this method in your code to append `League" to your file, that's why aschipfl's asked "are you seriously asking how to append a line...". – Stephan Mar 14 '17 at 15:54

1 Answers1

0

I am using FART for it. no, it means Find and Replace Text simply do this on your batch file fart.exe [filename] "old text" "replacing text" do the " ignore any [ and ]

http://fart-it.sourceforge.net/

Visual917
  • 43
  • 10
  • 1
    Your answer would be more helpful if you provided with an exact command. Also, I don't think your command will answer any of the authors questions. For the first one, he wants to add a line at the end of the file. For the second, he wants to replace the first line (no matter what text is on it). Please improve or remove your answer. – Loren Mar 14 '17 at 16:06