Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 Rook 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
add comment

1 Answer 1

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%

endlocal

http://stackoverflow.com/questions/10686261/write-batch-variable-into-specific-line-in-a-text-file

share|improve this answer
add comment

Your Answer

 
discard

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.