Announcement

Collapse
No announcement yet.

need a batch script to delete certain data from a dot c file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • need a batch script to delete certain data from a dot c file

    Hi all,
    I need a batch script to delete certain data from a dot c file so it needs to be open up with notepad and edited. i have multiply .c files all different names so i was wonder if someone can help me create a script to delete the following from each text file.there is more data in each file that i dont want removed. Thanks example bwlow



    Before Script:

    ROM_START( appoooh )
    ROM_REGION( 0x14000, REGION_CPU1, 0 ) /* 64k for code + 16k bank */
    ROM_LOAD( "epr-5906.bin", 0x00000, 0x2000, 0xfffae7fe )
    ROM_LOAD( "epr-5907.bin", 0x02000, 0x2000, 0x57696cd6 )
    ROM_LOAD( "epr-5908.bin", 0x04000, 0x2000, 0x4537cddc )
    ROM_LOAD( "epr-5909.bin", 0x06000, 0x2000, 0xcf82718d )
    ROM_LOAD( "epr-5910.bin", 0x08000, 0x2000, 0x312636da )
    ROM_LOAD( "epr-5911.bin", 0x0a000, 0x2000, 0x0bc2acaa ) /* bank0 */
    ROM_LOAD( "epr-5913.bin", 0x0c000, 0x2000, 0xf5a0e6a7 ) /* a000-dfff */
    ROM_LOAD( "epr-5912.bin", 0x10000, 0x2000, 0x3c3915ab ) /* bank1 */
    ROM_LOAD( "epr-5914.bin", 0x12000, 0x2000, 0x58792d4a ) /* a000-dfff */

    ROM_REGION( 0x0c000, REGION_GFX1, ROMREGION_DISPOSE )
    ROM_LOAD( "epr-5895.bin", 0x00000, 0x4000, 0x4b0d4294 ) /* playfield #1 chars */
    ROM_LOAD( "epr-5896.bin", 0x04000, 0x4000, 0x7bc84d75 )
    ROM_LOAD( "epr-5897.bin", 0x08000, 0x4000, 0x745f3ffa )

    ROM_REGION( 0x0c000, REGION_GFX2, ROMREGION_DISPOSE )
    ROM_LOAD( "epr-5898.bin", 0x00000, 0x4000, 0xcf01644d ) /* playfield #2 chars */
    ROM_LOAD( "epr-5899.bin", 0x04000, 0x4000, 0x885ad636 )
    ROM_LOAD( "epr-5900.bin", 0x08000, 0x4000, 0xa8ed13f3 )

    ROM_REGION( 0x0220, REGION_PROMS, 0 )
    ROM_LOAD( "pr5921.prm", 0x0000, 0x020, 0xf2437229 ) /* palette */
    ROM_LOAD( "pr5922.prm", 0x0020, 0x100, 0x85c542bf ) /* charset #1 lookup table */
    ROM_LOAD( "pr5923.prm", 0x0120, 0x100, 0x16acbd53 ) /* charset #2 lookup table */

    ROM_REGION( 0xa000, REGION_SOUND1, 0 ) /* adpcm voice data */
    ROM_LOAD( "epr-5901.bin", 0x0000, 0x2000, 0x170a10a4 )
    ROM_LOAD( "epr-5902.bin", 0x2000, 0x2000, 0xf6981640 )
    ROM_LOAD( "epr-5903.bin", 0x4000, 0x2000, 0x0439df50 )
    ROM_LOAD( "epr-5904.bin", 0x6000, 0x2000, 0x9988f2ae )
    ROM_LOAD( "epr-5905.bin", 0x8000, 0x2000, 0xfb5cd70e )
    ROM_END



    ROM_START( hooppe )
    ROM_REGION( 0x14000, REGION_CPU1, 0 ) /* 64k for code + 16k bank */
    ROM_LOAD( "epr-5906.bin", 0x00000, 0x2000, 0xfffae7fe )
    ROM_LOAD( "epr-5907.bin", 0x02000, 0x2000, 0x57696cd6 )
    ROM_LOAD( "epr-5908.bin", 0x04000, 0x2000, 0x4537cddc )
    ROM_LOAD( "epr-5909.bin", 0x06000, 0x2000, 0xcf82718d )
    ROM_LOAD( "epr-5910.bin", 0x08000, 0x2000, 0x312636da )
    ROM_END



    I need to delete all the following except for what below. So it should look like what i have underneath once done. the name in the parenthesis is always different fyi. Thanks!!!

    i have a script thatworks in a way but it delete everything else in the file which i dont want. pasted below.


    After Script:

    ROM_START( appoooh )
    ROM_END


    ROM_START( hooppe )
    ROM_END

    Code:
    @echo off
    setlocal enabledelayedexpansion
     
    for /f "delims=" %%A in ('dir /s /b *.c') do (
      set count=1
      for /f "delims=^( tokens=1,2" %%B in (%%A) do (
        if "%%B"=="ROM_START" (
          set out!count!=%%C
          set /a count+=1
        )
      )
      set /a stopcount=!count!-1
      set printcount=1
      for /l %%D in (1,1,!stopcount!) do (
        call set out=%%out!printcount!%%
        (echo ROM_START(!out!
        echo ROM_END
        echo.
        echo.) >>temp.txt
        set /a printcount+=1
      )
      del %%A
      ren temp.txt %%~nxA
    )
    Last edited by daillest319; 31st January 2012, 16:12.

  • #2
    Re: need a batch script to delete certain data from a dot c file

    You could probably do it easier by using macros inside MS Word. Visual Basic for Applications is the code base. It's fairly straightforward to search for a specific text string, select what you want (word, line paragraph), then delete the selection and move on. If you use a script in Windows to open the text files in Word, then set the macro to auto-run on open, do it's thing, then save the file & close, you'd be done.

    Or better yet, simply run everything inside the macro: open the files one at a time, run the clear-out, save and move on. Only close Word when the last file is done.
    *RicklesP*
    MSCA (2003/XP), Security+, CCNA

    ** Remember: credit where credit is due, and reputation points as appropriate **

    Comment


    • #3
      Re: need a batch script to delete certain data from a dot c file

      SED (preferable gSed for windows) is one of the utilities you can best use for the job.
      Download gnu sed (gSed) for Windows, free for download!

      Expand the download and copy the 4 files below from sed's 'bin' folder to the batch's folder
      sed.exe
      regex2.dll
      libiconv2.dll
      libintl3.dll


      Batch sample (to use with the gSed edition only)
      "Remove certain blocks occur in the file (define range: <address1>,<address2> ), but do not delete the first and last lines of each block":
      Code:
      @echo off
      
      :: define variables
      Set "InputFile=CfgFile.C"
      Set "OutputFile=tempfile.txt"
      
      
      :: convert unicode- to ansi format
      rem  type "%InputFile%" > "%InputFile%.tmp"
      rem  move /y "%InputFile%.tmp" "%InputFile%"
      
      :: define start and end strings of each block (using regular expression)
      Set "StartExp=^[ ]*ROM_START(.*$"
      Set "EndExp=^[ ]*ROM_END[ ]*$"
      
      :: run sed, output to temp file
      Set "SED=%~0\..\sed.exe"
      >"%OutputFile%" Call :GNU_SED
      
      :: enable the next line to actually overwrite(!) the original file with updated data
      rem  move /y "%OutputFile%" "%InputFile%"
      
      
      GOTO:EOF   - - - begin of sub routine - - -
      :GNU_SED only
      "%SED%" -e "/%StartExp%/,/%EndExp%/{/%StartExp%\|%EndExp%/!d}" "%InputFile%"
      exit /b 0
      /Rems


      (Similar posts
      http://forums.petri.com/showthread.p...211#post212211
      http://forums.petri.com/showthread.p...225#post253225
      http://forums.petri.com/showthread.p...802#post253802
      http://forums.petri.com/showthread.p...052#post255052

      http://forums.petri.com/showthread.p...230#post253230)
      Last edited by Rems; 9th March 2012, 18:57.

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment

      Working...
      X