Powershell Delete String in text file
Solved it, a quick amendment and here it is (get-content "L:\movement.txt") -notmatch "---" | out-file "L:\movement.txt"
Mr Deans
Perpetually learning and appreciative of the guidance that the world wide web provides. Ever thankful of stackover - flow...
Updated on June 05, 2022Comments
-
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 over 9 yearshope it helps someone else in the future!