Skip to main content
improved format for better reading. Fixed small grammar issues
Source Link

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 i justthat I don't want. how can I remove everything after and including the string.

This is what iI have - not working. Thank you so much.

$file = get-item "C:\Temp\test.txt"

(Get-Content $file) | ForEach {$_.TrimEnd("\test.something")} | Set-Content $file

$file = get-item "C:\Temp\test.txt"

(Get-Content $file) | ForEach {$_.TrimEnd("\test.something\")} | Set-Content $file

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 i just don't want. how can I remove everything after and including the string.

This is what i have - not working. Thank you so much.

$file = get-item "C:\Temp\test.txt"

(Get-Content $file) | ForEach {$_.TrimEnd("\test.something")} | Set-Content $file

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.

$file = get-item "C:\Temp\test.txt"

(Get-Content $file) | ForEach {$_.TrimEnd("\test.something\")} | Set-Content $file
Source Link
samsux
  • 87
  • 2
  • 3
  • 7

powershell trim - remove all characters after a string

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 i just don't want. how can I remove everything after and including the string.

This is what i have - not working. Thank you so much.

$file = get-item "C:\Temp\test.txt"

(Get-Content $file) | ForEach {$_.TrimEnd("\test.something")} | Set-Content $file