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

Author Topic: Remove characters from a text file  (Read 3355 times)

0 Members and 1 Guest are viewing this topic.

GeorgeF

    Topic Starter


    Newbie

    • Experience: Experienced
    • OS: Windows 10
    Remove characters from a text file
    « on: April 25, 2019, 06:24:23 AM »
    Hi, been struggling to get this to work.

    I have a txt file with 500 lines and growing, each line in the beginning has the text as the example below. I already have a batch file that joins 2 text files and one has K:\logs3\ and the other list just the files including folders.
    ex. K:\logs3\test.txt

    Its not a option to simple remove the folder as that would create more issues and more work. Therefore is the a way to remove these charaters form the line - K:\logs3\ ?

    Thanks in Advance
    « Last Edit: April 25, 2019, 07:01:17 AM by GeorgeF »

    GeorgeF

      Topic Starter


      Newbie

      • Experience: Experienced
      • OS: Windows 10
      Re: Remove characters from a text file
      « Reply #1 on: April 25, 2019, 08:33:19 AM »
      Manage to resolve my own problem but another issue has pop up concerning the same code.
      The code below removes the first 11 characters from a line in a text file. my issue now is to delete letters or characters in the middle of a text line. Example - I have C:\folder\doc - would like to remove "folder\ only and leave c:\ + doc.

      think the issue might be over here - set "line=!line:~0,11!"

      Thanks in Advance



      @echo off &setlocal
      (for /f "delims=" %%a in (list.txt) do (
          set "line=%%a"
          setlocal enabledelayedexpansion
          set "line=!line:~0,11!"
          echo(!line!
          endlocal
      ))>list.txt.new