motioneye
asked on
Powershell to truncate string in text
Guys,
I have a powershell script below use to truncate the string in the string_output2.txt however the script below doesn't work, what I would need to output is something like
this JJR3345-s-54007.maxis.kd.c om save in string_output22.txt
Get-Content (Get-ChildItem F:\Powershell\string_outpu t2.txt) | % {$_.Split(':')[1]} | Out-File F:\Powershell\string_outpu t22.txt
Here is contain in string_output2.txt
JJR3345-bs-54007:dbxsinstn ace:JJR334 5-s-54007. maxis.kd.c om
JJR3345-bs-54008:dbxsinstn ace:JJR334 5-s-54008. maxis.kd.c om
JJR3345-bs-54009:dbxsinstn ace:JJR334 5-s-54009. maxis.kd.c om
JJR3345-s-54025:dbxsinstna ce:JJR3345 -s-54025.m axis.kd.co m
JJR3345-s-54001:dbxsinstna ce:JJR3345 -s-54001.m axis.kd.co m
I have a powershell script below use to truncate the string in the string_output2.txt however the script below doesn't work, what I would need to output is something like
this JJR3345-s-54007.maxis.kd.c
Get-Content (Get-ChildItem F:\Powershell\string_outpu
Here is contain in string_output2.txt
JJR3345-bs-54007:dbxsinstn
JJR3345-bs-54008:dbxsinstn
JJR3345-bs-54009:dbxsinstn
JJR3345-s-54025:dbxsinstna
JJR3345-s-54001:dbxsinstna
That's a Unicode; use Out-File's -Encoding argument:
(Get-Content F:\Powershell\string_output2.txt) | % {$_.Split(':')[2]} | Out-File F:\Powershell\string_output22.txt -Encoding ASCII
ASKER
Hi oBdA
Yes I have tried that, still I have the same error as per screenshot
Yes I have tried that, still I have the same error as per screenshot
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi oBdA,
Thanks for help, I have to copy the text from one file and move to another new file, then the scripts worked with no flaw. thanks again for the assistance and the opinion
Thanks for help, I have to copy the text from one file and move to another new file, then the scripts worked with no flaw. thanks again for the assistance and the opinion
Open in new window