Batch file to search for and delete lines containing specific text
Solution 1
Perhaps you could use FIND
find /V "PO-" fdx.csv > new.csv
but you will get a header on the csv file that you have to remove manually
Solution 2
FINDSTR will work better;
findstr /v /i /b "PO-" fdx.csv > new.csv
/v will exclude lines with "PO-"
/b will only look for PO- at the beginning of the line
/i will make it case-insensitive (so Po-, po- pO-)
Or, with FIND, you could use MORE +x to skip x lines and remove the header it leaves behind;
more +1 | find /v "PO-" fdx.csv > new.csv
Related videos on Youtube
Hoehner
Updated on September 18, 2022Comments
-
Hoehner almost 2 years
I have a bat file that searches a directory for specific .csv files names, and copies and amends the lines into a new .csv file.
However, some of the lines of the original .csv files are not information needed, and begin with PO-. I'd like to add to my bat a way to search for cells containing "PO-" and delete the entire line, and then save the results in a new .csv file. Is it possible?.
What I have so far in my .bat file is:
REM @ Echo off Echo on type NUL>fdx.csv copy pds*.csv fdx.csv
-
Josh about 10 yearsIt would help if you were to post your batch file code.
-
Raystafarian about 10 yearsDo you want a .bat file or a macro for excel? You have both tagged.
-
Hoehner about 10 yearsSorry new to all of this. I'd like a .bat file. What I have in my .bat already is: type NUL>fdx.csv copy pds*.csv fdx.csv Echo on
-
sean christe about 10 yearsPlease edit your question to provide the requested information.
-
-
Scott - Слава Україні almost 4 yearsThis is the same as the accepted answer, but made more complicated with no benefit.