powershell trim – remove all characters after a string

Question:

What would be the command to remove everything after a string (\test.something).
I have information in a text file, but after the string there is like a 1000 lines of text that I don’t want. how can I remove everything after and including the string.

This is what I have – not working. Thank you so much.

Answer:

Why remove everything after? Just keep everything up to it (I’m going to use two lines for readability but you can easily combine into single command):

Also, you may not need the Trim but you were using TrimEnd so added in case you want to add it later. )

Source:

powershell trim – remove all characters after a string by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply