Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

remove end of a string

$
0
0

I have a .txt file that has the following

Joe@acme.org

Sam@acme.org

if I run the following code it will Add another @acme.org to the end of each line

(get-content"C:\Temp\name.txt") | foreach { $_+'@acme.org' } | set-content"C:\Temp\name.txt"

But if I change the + to a - it fails.  How come?  How do I remove @acme.org from each line?  

I've also tried this and neither one has worked.

 

(get-content"C:\Temp\name.txt") | foreach { $_-replace".*@"-replace",.*"}

$get=get-content"C:\Temp\name.txt"
$get.split('@')[1].split('')[0]


Viewing all articles
Browse latest Browse all 6937

Trending Articles