Powershell Delete String in text file

11,978

Solved it, a quick amendment and here it is (get-content "L:\movement.txt") -notmatch "---" | out-file "L:\movement.txt"

Share:
11,978
Mr Deans
Author by

Mr Deans

Perpetually learning and appreciative of the guidance that the world wide web provides. Ever thankful of stackover - flow...

Updated on June 05, 2022

Comments

  • Mr Deans
    Mr Deans almost 2 years

    I have a file that I am downloading daily what I want to do is create a script that reads the text file and deletes out any lines containing the string "---"

    I started with "(get-content L:\holdings.txt) | where {$_ -ne "" | out-file holdings.txt"

    This deletes all the blank lines without any issue, I then tried

    $del -like "*-*"
    "(get-content L:\holdings.txt) | where {$_ -ne $del | out-file L:\holdings.txt"
    

    Which I though would delete out any of the lines of data, whilst it runs without error the line is not being deleted out...

    I don't know if it's relevant but the line I want to delete will always be the second line as it is a comma delimited SQL batch file automation.

    The file reads as follows

    Advice Num ,Bargain Number
    --------------------,-----------------

    Just to try and give you a graphical representation that I am trying to resolve

    Any ideas?

    Regards

    Richard

  • Mr Deans
    Mr Deans over 9 years
    hope it helps someone else in the future!