powershell trim - remove all characters after a string -
what command remove after string (\test.something). have information in text file, after string there 1000 lines of text don't want. how can remove after , including string.
this have - not working. thank much.
$file = get-item "c:\temp\test.txt" (get-content $file) | foreach {$_.trimend("\test.something\")} | set-content $file
why remove after? keep (i'm going use 2 lines readability can combine single command):
$text = ( get-content test.txt | out-string ).trim() #note v3 can use get-content test.txt -raw $text.substring(0,$text.indexof('\test.something\')) | set-content file2.txt
also, may not need trim using trimend added in case want add later. )
Comments
Post a Comment