How to remove extra comma from line in text file in batch file?

Samraan

I'm trying to remove extra comma from end of the line in text file. Below is my approach:

set "n=%~,"
for %%t in (*.txt) do (
findstr /v /r /c:"$[%n%]*$" > res.txt
)

But it's no replacing the extra comma from text file. The content of text file as follows:

abc,asd,123,
1234,prq,456,,,,,
jkl,abc,9876,,,
5679,3459,gjh,,

I want the expected output as follows:

abc,asd,123
123,prq,456
jkl,abc,9878
5679,3459,gjh
Dale

I think substring will help you to get it done:

@echo off
setlocal EnableDelayedExpansion

for %%a in (*.txt) do (
    set txtPath=%%~fa
    echo !txtPath!
    for /f %%b in ('type "!txtPath!"') do (
        set line=%%b
        set output=!line!
        if "!line:~-1!"=="," (
            for /l %%i in (1,1,1000) do if "!output:~-1!"=="," set output=!output:~0,-1!
        )
        echo !output!>> res.txt
    )
)

As shown in the code above, It will help to trim up to 1,000 unwanted trailing comma and place the formatted output to a text file. You may refer to this link for more information about string manipulation in batch. Hope it helps.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to remove extra comma from line in text file in batch file?

From Dev

How to remove new line from text file in for loop (CMD/Batch)

From Dev

How to remove a line from a text file?

From Dev

How to remove first string and comma from a text file

From Dev

How to remove the last index of a comma from the text file?

From Dev

Remove a line from a file in Windows Batch

From Dev

how to read line 17 only from text file using batch

From Dev

Is there a way to remove the comma from a large number generated in a batch file?

From Dev

How to retrieve a random line from text file, then remove the line from the text file in PHP

From Dev

How to remove comma from a csv file with quotes?

From Dev

Batch, How To Read in a Blank Line of Text File

From Dev

how to remove duplicate line from text file vb.net

From Dev

How to remove the extra commas from a csv file?

From Dev

Parse a text file using batch script and remove the first 2 characters from each line

From Dev

Remove line breaks from text file

From Dev

How to remove comma from end of line in CSV file while exporting using C#

From Dev

Remove line 1 in a batch file

From Dev

Remove line 1 in a batch file

From Dev

Remove extra header lines from file, except for the first line

From Dev

How to create sub string in a line read from text file separated by comma

From Dev

How to delete a comma from every line of a file except the last line?

From Dev

Read a list of strings from text file and remove the extra quotes

From Dev

Removing Extra commas from Comma delimited file

From Dev

Batch Remove Whitespace in a Text File

From Dev

How to grep for line-separated strings containing a comma in a text file?

From Dev

how to remove comma and strings after a comma in a file?

From Dev

how to remove comma and strings after a comma in a file?

From Dev

Extracting text (from delim to end of line) from file - BATCH

From Dev

Batch: Remove linefeed from variable containing first line of file

Related Related

  1. 1

    How to remove extra comma from line in text file in batch file?

  2. 2

    How to remove new line from text file in for loop (CMD/Batch)

  3. 3

    How to remove a line from a text file?

  4. 4

    How to remove first string and comma from a text file

  5. 5

    How to remove the last index of a comma from the text file?

  6. 6

    Remove a line from a file in Windows Batch

  7. 7

    how to read line 17 only from text file using batch

  8. 8

    Is there a way to remove the comma from a large number generated in a batch file?

  9. 9

    How to retrieve a random line from text file, then remove the line from the text file in PHP

  10. 10

    How to remove comma from a csv file with quotes?

  11. 11

    Batch, How To Read in a Blank Line of Text File

  12. 12

    how to remove duplicate line from text file vb.net

  13. 13

    How to remove the extra commas from a csv file?

  14. 14

    Parse a text file using batch script and remove the first 2 characters from each line

  15. 15

    Remove line breaks from text file

  16. 16

    How to remove comma from end of line in CSV file while exporting using C#

  17. 17

    Remove line 1 in a batch file

  18. 18

    Remove line 1 in a batch file

  19. 19

    Remove extra header lines from file, except for the first line

  20. 20

    How to create sub string in a line read from text file separated by comma

  21. 21

    How to delete a comma from every line of a file except the last line?

  22. 22

    Read a list of strings from text file and remove the extra quotes

  23. 23

    Removing Extra commas from Comma delimited file

  24. 24

    Batch Remove Whitespace in a Text File

  25. 25

    How to grep for line-separated strings containing a comma in a text file?

  26. 26

    how to remove comma and strings after a comma in a file?

  27. 27

    how to remove comma and strings after a comma in a file?

  28. 28

    Extracting text (from delim to end of line) from file - BATCH

  29. 29

    Batch: Remove linefeed from variable containing first line of file

HotTag

Archive