Batch file to search for and delete lines containing specific text

14,146

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
Share:
14,146

Related videos on Youtube

Hoehner
Author by

Hoehner

Updated on September 18, 2022

Comments

  • Hoehner
    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
      Josh about 10 years
      It would help if you were to post your batch file code.
    • Raystafarian
      Raystafarian about 10 years
      Do you want a .bat file or a macro for excel? You have both tagged.
    • Hoehner
      Hoehner about 10 years
      Sorry 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
      sean christe about 10 years
      Please edit your question to provide the requested information.
  • Scott - Слава Україні
    Scott - Слава Україні almost 4 years
    This is the same as the accepted answer,  but made more complicated with no benefit.