I need a batch script to delete certain data from a .c file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
daillest319
Posts: 27
Joined: 31 Jan 2012 14:45

I need a batch script to delete certain data from a .c file

#1 Post by daillest319 » 31 Jan 2012 14:55

Hi all,
I need a batch script to delete certain data from a .c file. 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 file but at the same time NOT delete any other data in the file. The word in the parentheses of ROM_START( ? ) is always different but always ends with ROM_END



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



After Script:
ROM_START( appoooh )
ROM_END


ROM_START( hooppe )
ROM_END


Aacini
Expert
Posts: 1930
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: I need a batch script to delete certain data from a .c f

#2 Post by Aacini » 31 Jan 2012 16:40

Code: Select all

@echo off
setlocal EnableDelayedExpansion
for %%f in (*.c) do (
   findstr /N ^^ < "%%f" | find /C ":" > lines.tmp
   set /P lines=< lines.tmp
   call :ProcessFile < "%%f" > "%%~Nf.out"
)
goto :EOF

:ProcessFile
set i=0
:seekStart
   set line=
   set /P line=
   set /A i+=1
   if %i% gtr %lines% exit /B
   echo(!line!
if "!line:~0,9!" neq "ROM_START" goto seekStart
:seekEnd
   set line=
   set /P line=
   set /A i+=1
   if %i% gtr %lines% exit /B
if "!line!" neq "ROM_END" goto seekEnd
echo(!line!
goto seekStart


Test this code and, if the result is correct, add DEL "%%F" and REN "%%~NF.OUT" "%%~NXF" in the FOR loop after the CALL.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: I need a batch script to delete certain data from a .c f

#3 Post by Squashman » 31 Jan 2012 19:58

I had some code posted for this user on another forum. I guess he didn't check back there before posting here.

daillest319
Posts: 27
Joined: 31 Jan 2012 14:45

Re: I need a batch script to delete certain data from a .c f

#4 Post by daillest319 » 01 Feb 2012 11:04

thanks :D i didnt see you code to after squashman and thank for you help i ended up using your code.

Aacini -i had question about your code which workded perfect thank you.where am i adding DEL "%%F" and REN "%%~NF.OUT" "%%~NXF". your code works great as well but it creating two file.
Not sure if those lines are suppose to do anything regarding the two files. I added it after this line but nothing changed

Code: Select all

@echo off
setlocal EnableDelayedExpansion
for %%f in (*.c) do (
   findstr /N ^^ < "%%f" | find /C ":" > lines.tmp
   set /P lines=< lines.tmp
   call :ProcessFile < "%%f" > "%%~Nf.out"
   DEL "%%F"
   REN "%%~NF.OUT" "%%~NXF"


)
goto :EOF


alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: I need a batch script to delete certain data from a .c f

#5 Post by alan_b » 01 Feb 2012 16:00

daillest319 wrote:thanks :D i didnt see you code to after squashman and thank for you help i ended up using your code.

Aacini -i had question about your code which workded perfect thank you.where am i adding DEL "%%F" and REN "%%~NF.OUT" "%%~NXF". your code works great as well but it creating two file.


There are 26 variables %%a to %%z, plus another independent 26 from %%A to %%Z

i.e %%F is NOT defined by %%f

Upper case is different from lower case, unlike %VARIABLE% type !names! where the case is irrelevant.

Post Reply