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

Author Topic: Windows Batch/DOS - How to remove all lines from text file that end with '_' und  (Read 2531 times)

0 Members and 1 Guest are viewing this topic.

elwayisgod

    Topic Starter


    Greenhorn

    I have a file 'users.txt'.  It's just a listing of usernames:

    samt
    robw
    phil_
    bill_

    How can I remove all the lines that end with '_' and resave it as users.txt again using Windows Batch/DOS?

    sam

    DaveLembke



      Sage
    • Thanked: 662
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    I'd just use notepad and use the Replace ALL "_" with " " if you are talking about just a single text file that needs to be conditioned, and you are running Windows on this system.

    Then save it...

    elwayisgod

      Topic Starter


      Greenhorn

      Ended up with this and it seems to work ok:

      findstr /v _ users.txt > users2.txt

      move /y users2.txt users.txt

      ghostdog74



        Specialist

        Thanked: 27
        you might want to match an exact _ at the end of the line in case you do really have _ all over the line.

        .bat_man

        • Guest
        try this code
        assuming the file that contail the names is q.txt

        @echo off
        setlocal ENABLEDELAYEDEXPANSION
        for /f "" %%i in (q.txt) do (
        set r=%%i
        if "!r:~-1!" NEQ "_" echo %%i >>a   )
        move a q.txt
        endlocal