0

I'm looking for some help. I want to create a batch file that can find a particular line inside a text file and then insert a line below it and enter some text from the batch file.

Example I want to insert a line after "2"

Text file 1 2 3

The batch would find "2" create a new line and enter the word "Two". The number one would be within the text file, this could be any word.

The text file would be store on the C:\

@echo off
setlocal enabledelayedexpansion
ren in.txt in.tmp
set p=
for /f %%a in (in.tmp) do (
if "%%a"=="1" if "!p!"=="3" Echo Two >> in.txt
Echo %%a >>in.txt
set p=%%a
)
del in.tmp
IanC
  • 11
  • 1
  • 1
    Pure code-writing requests are off-topic on Stack Overflow -- we expect questions here to relate to *specific* programming problems -- but we will happily help you write it yourself! Tell us [what you've tried](https://stackoverflow.com/help/how-to-ask), and where you are stuck. This will also help us answer your question better. – glennsl Sep 29 '17 at 11:39
  • 1
    Possible duplicate of [How can you find and replace text in a file using the Windows command-line environment?](https://stackoverflow.com/questions/60034/how-can-you-find-and-replace-text-in-a-file-using-the-windows-command-line-envir) – Mofi Sep 29 '17 at 12:02
  • I've added what i've got so far to the original comment. – IanC Sep 29 '17 at 20:02
  • You should also provide an explanation regarding any issues or errors resulting from the invokation of your script and if or how that differs from your intent. – Compo Sep 29 '17 at 21:36

0 Answers0