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

Author Topic: In need of a batch file to remove position in text file  (Read 4061 times)

0 Members and 1 Guest are viewing this topic.

swinters

    Topic Starter


    Rookie

    In need of a batch file to remove position in text file
    « on: May 30, 2012, 09:42:59 AM »
    I need a batch file that will delete position 805 in every row of a text file.  Any help would be appreciated!

    Salmon Trout

    • Guest
    Re: In need of a batch file to remove position in text file
    « Reply #1 on: May 30, 2012, 11:06:53 AM »
    Could you please be a bit more clear? Do you mean you want to read a text file, line by line, and delete the 805th character of each line? That is, the new line will be characters 1 to 804, and then characters 806 to the end?

    swinters

      Topic Starter


      Rookie

      Re: In need of a batch file to remove position in text file
      « Reply #2 on: May 30, 2012, 11:46:24 AM »
      Yes - start with report1.txt.....have the batch file copy it to another file (report2) with the 805th character removed.  Thanks for the response!! :-)

      Salmon Trout

      • Guest
      Re: In need of a batch file to remove position in text file
      « Reply #3 on: May 30, 2012, 12:54:22 PM »
      try this, it should work as long as report1.txt does not contain any poison characters-

      Code: [Select]
      @echo off
      setlocal enabledelayedexpansion
      REM batch strings are indexed starting at 0
      REM first part starts at character index 0
      REM and is 804 characters long
      set firstpartlength=804
      REM last part starts at character index 805 (the 806th char)
      set lastpartstart=805
      if exist report2.txt del report2.txt
      for /f "delims=" %%A in (report1.txt) do (
      set string1=%%A
      echo !string1:~0,%firstpartlength%!!string1:~%lastpartstart%! >> report2.txt
      )

      swinters

        Topic Starter


        Rookie

        Re: In need of a batch file to remove position in text file
        « Reply #4 on: May 30, 2012, 02:16:36 PM »
        Salmon Trout - This worked perfectly....thank you so much for your help!!! :D