sed -e s/^String.*$/String/g file.txt > output.txt
===========================================================================================
Met les lignes dans  %var[n]%
@echo off
setlocal enabledelayedexpansion

set count=0

for /f "tokens=*" %%x in (file1.txt) do (
    set /a count+=1
    set var[!count!]=%%x
)

echo %var[3]%
=========================================================================================
Remplacer la ligne contenant le mot "sky" par une ligne "I find the word"
I think you haven't tested my code, or I haven't tested it enough... ;)
find /v will pass thru all lines that do not contain 'sky' (I haven't redirected find results to nul)
if 'sky' is found (meaning || will trigger echo) -> replacement line will go down the stream.
But you are right about blank lines, always forget about this 'feature' of for /f  :(

for /f "delims=" %L in (test.txt) do @echo %L | find /v "sky" || echo I find the word

If stored in batch - use %%L instead of %L. If you want to save it in a file - just redirect result to it:
(for /f "delims=" %L in (test.txt) do @echo %L | find /v "sky" || echo I find the word) > test2.txt

=========================================================================================
remplacer 
extension=
posicion=
par
extension=3438
posicion=3438
You can't add in the middle of the file but you can write the new content to a temporary file and afterwards replace the original file.

@echo off &setlocal
set "file=test.txt"

set /p "extension=extension="
set /p "posicion=posicion="

setlocal EnableDelayedExpansion
<"!file!" >"!file!.~tmp" (
  for /f %%i in ('type "!file!"^|find /c /v ""') do for /l %%j in (1 1 %%i) do (
    set "line=" &set /p "line="
    if "!line:~,10!"=="extension=" (
      echo(extension=!extension!
    ) else if "!line:~,9!"=="posicion=" (
      echo(posicion=!posicion!
    ) else (
      echo(!line!
    )
  )
)
>nul move /y "!file!.~tmp" "!file!"
====================================================================================================
Replacing nth line of a file 
    The main script calls the function replaceLine, with the filename/ which line to change/ and the string to replace.

    Function receives the input
        It loops through all the lines and echo them to a temporary file before the replacement line
        It echoes the replacement line to the file
        It continues to output to rest of the file
        It copies the temporary file to the original file
        And removes the temporary file.

    The main script gets the control back, and type the result.

@echo off
set file=new2.txt

call :replaceLine "%file%" 3 "stringResult"

type "%file%"
pause
exit /b

:replaceLine <fileName> <changeLine> <stringResult>
setlocal enableDelayedExpansion

set /a lineCount=%~2-1

for /f %%G in (%~1) do (
    if !lineCount! equ 0 pause & goto :changeLine
    echo %%G>>temp.txt
    set /a lineCount-=1
)

:changeLine
echo %~3>>temp.txt

for /f "skip=%~2" %%G in (%~1) do (
    echo %%G>>temp.txt
)

type temp.txt>%~1
del /f /q temp.txt

endlocal
exit /b
====================================================================================================
I got a task in hand to remove all YAML files id to null. :
The for loop has some option, where tokens= specify which numbered items to read from each line (default =1) and delims= specify the delimiter character (default = a space). The %%paramater are variables similar to arguments to batch files. The last line export the result to the file I want. It saves a lot of time with this simple script instead of doing manual work :)

@echo off
(for /f "tokens=1* delims=:" %%a in (temp.yaml) do (
 if "%%b"=="" (echo %%a) else (
  echo %%a|find " id" >null&& echo %%a: ||echo %%a: %%b
 )
))>result.yaml
====================================================================================================
This example replaces the line if it matches "::replace" exactly, not contains. 
The first example replaces the line in the main script itself:

@echo off
set "infile=%~0"
for /f "delims=" %%i in ('type "%infile%" ^| find /v /n "" ^& break^>%infile%') do (
    set "line=%%i"
    setlocal enabledelayedexpansion
    set "line=!line:*]=!"
    if "!line!" == "::replace" (
       set line=
       type replace_file.txt
    )>>!infile!
    echo(!line!>>!infile!
    endlocal
 )

rem sample replace section here.
@echo off
echo hello world
::replace
pause>nul



This example replaces the line if it matches ::replace exactly, not contains. The first example replaces the line in the main script itself:

@echo off
set "infile=%~0"
for /f "delims=" %%i in ('type "%infile%" ^| find /v /n "" ^& break^>%infile%') do (
    set "line=%%i"
    setlocal enabledelayedexpansion
    set "line=!line:*]=!"
    if "!line!" == "::replace" (
       set line=
       type replace_file.txt
    )>>!infile!
    echo(!line!>>!infile!
    endlocal
 )

rem sample replace section here.
@echo off
echo hello world
::replace
pause>nul

To have it replace the lines in another batch file, then add the name of the file where it says "ADD FILE NAME HERE":
 this is replacing the script itself by breaking the original and re-creating it while replacing what you ask it to. 
@echo off

@echo off
set "infile=ADD FILE NAME HERE"
for /f "delims=" %%i in ('type "%infile%" ^| find /v /n "" ^& break^>%infile%') do (
    set "line=%%i"
    setlocal enabledelayedexpansion
    set "line=!line:*]=!"
    if "!line!" == "::replace" (
       set line=
       type replace_file.txt
    )>>!infile!
    echo(!line!>>!infile!
    endlocal
 )
==============================================================================================
 For each line, if it starts with "String ", then write "String" to the output; otherwise write the original line.

copy nul output.txt
for /f "tokens=1* delims=:" %%a in ('findstr /n "^" file.txt') do call :do_line "%%b"
goto :eof

:do_line
set line=%1
if {%line:String =%}=={%line%} (
  echo.%~1 >> output.txt
  goto :eof
)
echo string >> output.txt
===============================================================================================
@echo off &setlocal
set "search=%1"
set "replace=%2"
set "textfile=Input.txt"
set "newfile=Output.txt"
(for /f "delims=" %%i in (%textfile%) do (
    set "line=%%i"
    setlocal enabledelayedexpansion
    set "line=!line:%search%=%replace%!"
    echo(!line!
    endlocal
))>"%newfile%"
del %textfile%
rename %newfile%  %textfile%
=================================================================================================
for /f will read all the data (generated by the type comamnd) before starting to process it. 
In the subprocess started to execute the type, we include a redirection overwritting the file 
(so it is emptied). Once the do clause starts to execute (the content of the file is in memory to be processed) the output is appended to the file.
@echo off 
    setlocal enableextensions disabledelayedexpansion

    set "search=%1"
    set "replace=%2"

    set "textFile=Input.txt"

    for /f "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile%" ') do (
        set "line=%%i"
        setlocal enabledelayedexpansion
        >>"%textFile%" echo(!line:%search%=%replace%!
        endlocal
    )