| 1. |
Solve : Echo + Append text to specific line in a txt file..??? |
|
Answer» is there a way to echo + Append TEXT into a specific line in a .txt file.. 1---:And you want to add !!!..Echoed in txt here..!!! on the fifth line?yup, u got it, thas wat i wana do.. can it be done..??With the other tools available on modern machines, why did you pick a batch solution? Code: [Select]@echo off setlocal enabledelayedexpansion set count=0 for /f %%i in (input.txt) do ( call set /a count=%%count%%+1 if !count!==5 (set line=%%i ..Echoed in txt here..) else (set line=%%i) echo !line!>>output.txt ) This comes dangerously close to programming and we all know batch coding is not a programming language. Note: Exclamation marks (!) have special meaning in batch files. If you must absolutely have them, you'll need to work that part of the solution yourself. thanks for the help.. but this seems to just duplicate the input.txt file into the output.txt then appends then new text into the output.txt.. I need it to append the new text to the 5th line on the original input.txt Quote I need it to append the new text to the 5th line on the original input.txt That is not going to happen. Batch code can only process sequential files. Sequential files cannot be updated in place (cannot be opened both input and output at the same time). If the new record were larger than the old record, how would it fit into the old space? Here is one workaround: Code: [Select]@echo off setlocal enabledelayedexpansion set count=0 for /f %%i in (input.txt) do ( call set /a count=%%count%%+1 if !count!==5 (set line=%%i ..Echoed in txt here..) else (set line=%%i) echo !line!>>output.txt ) ren input.txt input.old ren output.txt input.txt I dislike writing destructive code but the first ren command can be replaced by a del command. |
|