Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to inject a string into the file at a given line/column position in a file, and have it overwrite any existing characters (as if the insert key was pressed in an editor). Is there a way to inject a string at a position in windows cmd?

share|improve this question
Do you mean via a script or manually? You can use the mouse and keyboard - Move the cursor via your keyboard to where you want the string to be inserted, right click your mouse on the CMD box and select paste. – Dave Oct 24 '12 at 7:41
@DaveRook I'm looking to do it via a script, sorry I didn't clarify. – Suchipi Oct 24 '12 at 17:31
Does this help? – Karan Oct 24 '12 at 19:24
Yes it does. Thank you, @Karan – Suchipi Oct 24 '12 at 20:25
up vote 1 down vote accepted

Answer in comments of OP:

@echo off
setlocal enableextensions enabledelayedexpansion

set inputfile=variables.txt

set tempfile=%random%-%random%.tmp

copy /y nul %tempfile%

set line=0

for /f "delims=" %%l in (%inputfile%) do (
    set /a line+=1
    if !line!==4 (
        echo WORDS YOU REPLACE IT WITH>>%tempfile%
    ) else (
        echo %%l>>%tempfile%

del %inputfile%
ren %tempfile% %inputfile%


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.