Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch file to Copy certian lines in a txt file only  (Read 13785 times)

0 Members and 1 Guest are viewing this topic.

millergram

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Windows Vista
    Batch file to Copy certian lines in a txt file only
    « on: July 01, 2012, 06:00:12 PM »
    Hello Haven't been on in a while been doing lots of stuff and learning ;D
    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 Glove
    I 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.txt
    Problem being I don't know how to filter out the unnecessary things

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: Batch file to Copy certian lines in a txt file only
    « Reply #1 on: July 01, 2012, 07:56:34 PM »
    @echo off
    for /F "tokens=1 delims= " %%G in ('type file.txt ^|findstr /C:"WEAP"') do (
    >>output.txt echo %%G
    )
    « Last Edit: July 01, 2012, 08:19:51 PM by Squashman »

    millergram

      Topic Starter


      Rookie

      • Experience: Beginner
      • OS: Windows Vista
      Re: Batch file to Copy certian lines in a txt file only
      « Reply #2 on: July 01, 2012, 08:25:25 PM »
      Thank you doesn't do exactly what i want but makes things so much easier wish i had known about the findstr command sooner

      Squashman



        Specialist
      • Thanked: 134
      • Experience: Experienced
      • OS: Other
      Re: Batch file to Copy certian lines in a txt file only
      « Reply #3 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!

      Squashman



        Specialist
      • Thanked: 134
      • Experience: Experienced
      • OS: Other
      Re: Batch file to Copy certian lines in a txt file only
      « Reply #4 on: July 01, 2012, 09:03:51 PM »
      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.

      millergram

        Topic Starter


        Rookie

        • Experience: Beginner
        • OS: Windows Vista
        Re: Batch file to Copy certian lines in a txt file only
        « Reply #5 on: July 04, 2012, 09:52:10 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%
        )

        Squashman



          Specialist
        • Thanked: 134
        • Experience: Experienced
        • OS: Other
        Re: Batch file to Copy certian lines in a txt file only
        « Reply #6 on: July 05, 2012, 06:21:12 AM »
        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.