Home / Microsoft / Microsoft DOS / need help! need a batch script to delete certain data from a .c file
0 Members and 2 Guests are viewing this topic. « previous next »
Pages: 1 2 [All] - (Bottom) Print
Author Topic: need help! need a batch script to delete certain data from a .c file  (Read 399 times)
daillest319
Topic Starter
Rookie



Posts: 16

Experience: Beginner
OS: Unknown

« on: January 30, 2012, 05:34:31 PM »

Hi all,
I need a batch script to delete certain data from a .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.

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!!! :D


After Script:

ROM_START( appoooh )
ROM_END


ROM_START( hooppe )
ROM_END

IP logged
Raven19528
Hopeful



Thanked: 29
Posts: 284

Computer: Specs
Experience: Experienced
OS: Windows 7



« Reply #1 on: January 30, 2012, 05:46:29 PM »

Two questions to start with:

1. Is this:
Code: [Select]
ROM_START( appoooh )
ROM_END


ROM_START( hooppe )
ROM_END
all that is going to be left in the file? (i.e. Is that the entire file you are showing, or only part of it?)

2. Where did the ( hooppe ) come from? I don't see that anywhere in your starting text.

IP logged

"All things that are
Are with more spirit chased than enjoy'd" -Shakespeare
daillest319
Topic Starter
Rookie



Posts: 16

Experience: Beginner
OS: Unknown

« Reply #2 on: January 30, 2012, 05:50:06 PM »

1. no there more data within the file.  Basically i need to find ROM_START( appoooh ) and delete all the data between ROM_START( appoooh )  and ROM_END and collapse so there near each other like i wrote above. The thing is the words are always different for example  can ROM_START( hooppe ) or something random.



2.  (hooppe) was the last group of lines at the bottom on the original post


i attached  two files that need it to be done. i have about 100 more . also i made these .txt there originally .c
« Last Edit: January 30, 2012, 06:10:46 PM by daillest319 » IP logged
Raven19528
Hopeful



Thanked: 29
Posts: 284

Computer: Specs
Experience: Experienced
OS: Windows 7



« Reply #3 on: January 30, 2012, 06:33:36 PM »

Then try this:
Code: [Select]
@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
  )
  echo del %%A
  echo ren temp.txt %%~nxA
  pause
)

Check the temp.txt file and ensure that the DEL and REN commands line up like you want them too, then remove the pause and the last two echos and let her run. I haven't tried this with subfolders, but it did work on the test file that I used within the same folder. It might be as simple as moving the file to the correct location once it is renamed. That would look like this
Code: [Select]
move %%~nxA %%~dpA and this line would be added in under the REN command before the final closing parenthesis. Run the code as it is first and see if that modification is needed.

Let us know if it doesn't work as expected.
IP logged

"All things that are
Are with more spirit chased than enjoy'd" -Shakespeare
daillest319
Topic Starter
Rookie



Posts: 16

Experience: Beginner
OS: Unknown

« Reply #4 on: January 30, 2012, 07:08:27 PM »

nothing happens not sure why. its says continue but it doesn't do anything. But at the the top it says

The system cannot find the file Jr\Downloads\mame\aeroboto.c

IP logged
daillest319
Topic Starter
Rookie



Posts: 16

Experience: Beginner
OS: Unknown

« Reply #5 on: January 30, 2012, 07:17:31 PM »

it deleting the data between the lines but  its also deleting everything in the file instead of only removing only whats between those two lines. otherwise it would be perfect
« Last Edit: January 30, 2012, 08:15:52 PM by daillest319 » IP logged
Geek-9pm
Sage



Thanked: 373
Posts: 8,928

Computer: Specs
Experience: Expert
OS: Windows XP


Geek After Dark

Geek 9pm blog
« Reply #6 on: January 30, 2012, 11:15:22 PM »

Another method.  Do it is bite size jobs.
A short BAT file removes all line that start withe  "ROM_LOAD"
first try this on a file:
find  "ROM_LOAD" aeroboto.c
OK?
Now try this:
find  /V "ROM_LOAD" aeroboto.c
Did you like that?
Now:
find  /V R"OM_LOAD" aeroboto.c >> aerobot.c2
Will that work for you?
IP logged

daillest319
Topic Starter
Rookie



Posts: 16

Experience: Beginner
OS: Unknown

« Reply #7 on: January 31, 2012, 06:57:59 AM »

Thing is it has to be after the parentheses and the word in the parentheses ROM_START( appoooh ) is always different. So the appoooh is always different but in each file it always look just lik what i wrote in my first post.

The first code above would be perfect if it didnt delete eveything else in the file because its doing excatly what i need to be done but i need it not to delete everything else in the file.
IP logged
Squashman
Hopeful



Thanked: 25
Posts: 342

Experience: Experienced
OS: Other



« Reply #8 on: January 31, 2012, 07:57:29 AM »

Just looking at your text file examples it looks like we could delete any line that begins with ROM_LOAD, ROM_REGION or ROM_LOAD16_BYTE.
IP logged
daillest319
Topic Starter
Rookie



Posts: 16

Experience: Beginner
OS: Unknown

« Reply #9 on: January 31, 2012, 08:06:38 AM »

theres also ROM_COPY in some  but i was looking throught more the files ands there also other data in alot of the file that between  ROM_START(  ) and ROM_END that need to be deleted as well so it wouldnt work right.
IP logged
Squashman
Hopeful



Thanked: 25
Posts: 342

Experience: Experienced
OS: Other



« Reply #10 on: January 31, 2012, 08:17:22 AM »

Seems like it would be easier for you to write a C program to do this.
We have a dedicated C programmer on staff.  If there is something we can't do with our data processing software that is very specific we have him write a C program.  And even before that I usually try something with batch but batch is very slow at processing very large files so I will usually resort to having the program written in C.
IP logged
daillest319
Topic Starter
Rookie



Posts: 16

Experience: Beginner
OS: Unknown

« Reply #11 on: January 31, 2012, 09:28:33 AM »

 :-\ im going to keep trying to figure something out. i dont know anything about C programming and im new to writing scripts in genral. so hopefully there a way to edit what i have to not delete everytihg else in the text file. thanks for everyone thats been helping me
IP logged
Raven19528
Hopeful



Thanked: 29
Posts: 284

Computer: Specs
Experience: Experienced
OS: Windows 7



« Reply #12 on: January 31, 2012, 12:00:37 PM »

I didn't see your edit. Yes the batch was only going to have the ROM_START in it and would delete everything else. C programming would probably be a more effecient way of doing this, but batch would allow for it to happen, it is just going to take more processing time and it's a lot different code. I'll work on something today that hopefully will get you on the right track.
IP logged

"All things that are
Are with more spirit chased than enjoy'd" -Shakespeare
daillest319
Topic Starter
Rookie



Posts: 16

Experience: Beginner
OS: Unknown

« Reply #13 on: January 31, 2012, 12:11:47 PM »

THANK YOU I REALLY APPERCIATE IT
IP logged
Squashman
Hopeful



Thanked: 25
Posts: 342

Experience: Experienced
OS: Other



« Reply #14 on: January 31, 2012, 01:52:23 PM »

Hey Raven, here is some code I worked out.  I just wanted to get the code working for one file right now and it seems to work fine.  The reason I am doing it this way was to preserve the blank lines otherwise the FOR LOOP will discard the blank lines.

Just need to wrap another loop around this to iterate all the input files.  I gotta get going for the day.

Code: [Select]
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set _FILE=argus.txt
set _WRITE=ON
FOR /F "USEBACKQ delims=" %%A IN (`TYPE "%_FILE%" ^| FIND.exe /V /N ""`) DO (
  SET "LN=%%A"
  SET "LN=!LN:*]=!"
  IF "!LN:~0,7!"=="ROM_END" set _WRITE=ON
  IF "!_WRITE!"=="ON" ECHO(!LN!>>"%_FILE%.tmp"
  IF "!LN:~0,9!"=="ROM_START" set _WRITE=OFF
)
IP logged
Raven19528
Hopeful



Thanked: 29
Posts: 284

Computer: Specs
Experience: Experienced
OS: Windows 7



« Reply #15 on: January 31, 2012, 06:06:08 PM »

Funny, I did something almost exactly the same, but I was away from my computer for an extended period.

The code below iterates what you are wanting. You can either use this or Squashman's code (use in place of the second FOR loop in mine) and it should give you the results that you are looking for.

Code: [Select]
@echo off
setlocal enabledelayedexpansion
set switch=0

for /f "delims=" %%A in ('dir /s /b *.c') do (
  for /f "delims=^( tokens=1*" %%B in (%%A) do (
    if !switch! equ 0 (
      if "%%B"=="ROM_START" (set switch=1)
      echo %%B^(%%C >>temp.txt
    )
    if !switch! equ 1 (
      if "%%B"=="ROM_END" (
        set switch=0
        echo ROM_END >> temp.txt
      )
    )
  echo del %%A
  echo ren temp.txt %%~nxA
  )
)

Same rules as above with the removing the echo and adding move if needed. Let us know how this works.
IP logged

"All things that are
Are with more spirit chased than enjoy'd" -Shakespeare
daillest319
Topic Starter
Rookie



Posts: 16

Experience: Beginner
OS: Unknown

« Reply #16 on: January 31, 2012, 06:54:21 PM »

Thank you raven and squashman for all your help  ;D
IP logged
Pages: 1 2 [All] - (Top) Print 
Home / Microsoft / Microsoft DOS / need help! need a batch script to delete certain data from a .c file « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.168 seconds with 19 queries.