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

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

ios - Possible to get UIButton sizeThatFits to work? -