Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- EDLIN - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

    Using EDLIN scripts


    Two examples of batch files using EDLIN and redirection of input and
    output. Both files have been slightly changed for clarity.

    EDLOOP.BAT appeared in PC Magazine 1991-05-28 (Vol. 10, no. 10)
    REPL.BAT appeared in PC Magazine 1990-11-13 (Vol. 9 no. 19)

    ---------------------------------------------------------------------

      @echo off

    rem EDLOOP.BAT -- creates a batch file to repetitively execute a
    rem series of commands.  In this case ring the doorbell.

      if "%1"=="" goto NEEDNUMBER

    rem  Open the file ring.bat with the statements to be reiterated

       echo echo DING DONG > ring.bat
       echo echo **** **** >> ring.bat

    rem  Create input for the Edlin script
    rem  Use the copy count option & delete the first existence
    rem  Multiple commands on one line must be separated with a
    rem  semicolon

      echo 1,2,1,%1C;1,2D;E; > edlininp.dat
      edlin ring.bat < edlininp.dat >nul

    rem  Run the reiterative batch job & tidy up

      call ring.bat
      erase edlininp.dat
      erase ring.*
      goto DONE

    :NEEDNUMBER

      ECHO The syntax should be
      ECHO     EDLOOP n
      ECHO where n is the number of iterations

    :DONE

    -----------------------------------------------------------------------

    The following batch file creates a DEBUG script that creates an EDLIN
    script to make a simple text search-and-replace utility. DEBUG is used
    to put the Ctrl-Z character (1Ah) that EDLIN needs for the Replace Text
    command into TEMPEDLN.SCR. The script and log files are listed below.


    REPL.BAT

    @ECHO OFF
    REM This is REPL.BAT
    IF '%3'=='' GOTO explain
    ECHO Now checking for valid parameters . . .
    ECHO %2 | FIND "%1" > XXXXXXXX.TMP
    REM Only if %2 contained %1 will the tempfile be
    REM non-empty.  DOS won't copy an empty file.  So
    REM if the second tempfile exists, %2 DID contain %1.
    COPY XXXXXXXX.TMP YYYYYYYY.TMP > NUL
    DEL XXXXXXXX.TMP > NUL
    IF EXIST YYYYYYYY.TMP GOTO BadParams
    ECHO Replacing "%1" with "%2" in files matching:
    ECHO %3 %4 %5 %6 %7 %8 %9
    :--------------------------------------------------
    ECHO Now creating DEBUG script. . .
    ECHO NTEMPEDLN.SCR > TEMPDEBG.SCR
    ECHO E CS:100 '1R%1' 1A '%2' 0D 0A 'E' 0D 0A 1A >> TEMPDEBG.SCR
    ECHO RCX >> TEMPDEBG.SCR
    ECHO 40 >> TEMPDEBG.SCR
    ECHO W >> TEMPDEBG.SCR
    ECHO Q >> TEMPDEBG.SCR
    :--------------------------------------------------
    ECHO Now creating EDLIN script . . .
    DEBUG < TEMPDEBG.SCR > NUL
    DEL TEMPDEBG.SCR
    ECHO Replacing "%1" with "%2" in files matching: > REPL.LOG
    ECHO %3 %4 %5 %6 %7 %8 %9 >> REPL.LOG
    :--------------------------------------------------
    ECHO Now performing replacement . . .
    FOR %%f IN (%3 %4 %5 %6 %7 %8 %9) DO EDLIN %%f < tempedln.scr >> REPL.LOG
    DEL TEMPEDLN.SCR
    ECHO To see a log of the work REPL.BAT did, read the file REPL.LOG
    GOTO end
    :BadParams
    DEL YYYYYYYY.TMP > NUL
    ECHO Unfortunately, the string "%2" _contains_
    ECHO the string "%1".  REPL.BAT can't handle that.
    GOTO end
    :Explain
    ECHO SYNTAX: "REPL findstr replacestr filespec [filespec...]
    ECHO This batch program will search files matching up to 7
    ECHO file specifications and replace all occurrences of the
    ECHO "find string" with the "replace string" in each file.
    :end



    TEMPDEBG.SCR

    NTEMPEDLN.SCR
    E CS:100 '1Rpush' 1A 'PUSH' 0D 0A 'E' 0D 0A 1A
    RCX
    40
    W
    Q



    TEMPEDLN.SCR

    1Rpush^ZPUSH
    E
    ^Z



    REPL.LOG

    Replacing "push" with "PUSH" in files matching:
    *.asm
    End of input file
    *1Rpush^ZPUSH
    Not found
    *E
    End of input file
    *1Rpush^ZPUSH
       146:      PUSHf
       147:      PUSH    ds
       148:      PUSH    es
       149:      PUSH    ax
       150:      PUSH    bx
       151:      PUSH    cx
       152:      PUSH    dx
       153:      PUSH    di
       154:      PUSH    si
    *E
    End of input file
    *1Rpush^ZPUSH
       367:      PUSH    ax
       402:      PUSH    es
    *E
    End of input file
    *1Rpush^ZPUSH
    Not found
    *E
    End of input file
    *1Rpush^ZPUSH
    Not found
    *E

    ---------------------------------------------------------------------

    This batch file tests for EDLIN presence:

    @echo off
    rem     DOS will accept a 'Bad Command' with an errorlevel of zero.
    rem     EDLIN will terminate with an errorlevel of 255 if called with
    rem     no file name (correct format is: EDLIN filename.ext [/B]).
    edlin > nul
    if errorlevel 1 goto IS_EDLIN
    echo EDLIN is not in path.
    goto EO_BAT
    :IS_EDLIN
    echo EDLIN is in path.
    :EO_BAT

    ---------------------------------------------------------------------

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson