1.

Solve : Batch file to Copy certian lines in a txt file only?

Answer»

Hello Haven't been on in a while been doing lots of stuff and learning
Im making a mod for fallout new vegas on the 360 and need a batch file that will
1.look at each line in a txt file and IGNORE lines without the prase "WEAP"
2.copy the FIRST 8chars into a new txt file line per line
and the data in the txt file its copying from looks LIKE this:
Code: [Select]01004746 NVDLC03PlayerTrunk CONT Trunk
01009701 NVDLC03WeapProtonAxeInversal WEAP Protonic Inversal Axe
01006DB3 NVDLC03SLVillageBorousBINT CELL Basement
0100A130 NVDLC03WeapGlovesCorrosive WEAP Corrosive GloveI know i will need to use delims and tokens but those are my weak points
so if anyone could help me There would be many thanks
I believe the script would go along the lines of:
Code: [Select]@echo off
for /F "tokens=1" %%i in (file.txt) do echo %%i>output.txtProblem being I don't know how to filter out the unnecessary things@echo off
for /F "tokens=1 delims= " %%G in ('type file.txt ^|findstr /C:"WEAP"') do (
>>output.txt echo %%G
)Thank you doesn't do exactly what i want but makes things so much easier wish i had known about the findstr command soonerWhat do you mean it doesn't do exactly what you want. That is exactly what you asked for!I see now. That is a TAB delimited text file. Just remove the DELIMS option. By default a FOR LOOP will delimit by a tab and a space when you don't specify the delimiter.Quote from: Squashman on July 01, 2012, 08:52:45 PM

What do you mean it doesn't do exactly what you want. That is exactly what you asked for!
Well I wanted one batch file to do all the work but your solution wasnt spot on because my lack of explanation Probably
But I figured it out Thanks to you and made these two batch files That completely solve the Problem
This One Prepares The file for Reading (Basically):
Code: [Select]@echo off
Echo.Catagories
echo.ARMO=Armor MISC=misc ALCH=AID NOTE=notes WEAP=Weapons AMMO=ammo WeaponMods=IMOD
set /p A=Ammout:
set /p C=Catagories:
set /p filename=Filename:
set /p B=OutputFilename:
for /F "tokens=1 delims= " %%I in ('type %filename% ^|findstr "%C%"') do (
>>%B% echo %%I
)
call SortIDs.bat
pause
And this one finished it Up:
Code: [Select]for /F "tokens=1" %%G in (%B%) do (
>>%B% echo player.additem %%G %A%
)
Quote from: millergram on July 04, 2012, 09:52:10 PM
Well I wanted one batch file to do all the work but your solution wasnt spot on because my lack of explanation Probably
My solution was spot on given the information you gave me. You never said anything about that extra code you have for you 2nd batch file.


Discussion

No Comment Found