Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing line break powershell

I am having an issue with a line break in my data. The array was made with an out-string followed by -split. If you want to see that part of the script let me know.

foreach ($item in $array) {
"_"+$item+"_"
}

Output:

_
itemname_

Desired Output:

itemname

I've tried inserting:

$item.replace('`','')

Without any change. Any ideas?

like image 367
snoop Avatar asked Mar 06 '14 23:03

snoop


2 Answers

Okay, I think this should work. I was under the impression you wanted those underscores in the result.

$array -replace "`n|`r"
like image 135
mjolinor Avatar answered Oct 05 '22 23:10

mjolinor


By default, 'Get-Content' command has the default delimiter of a new line '\n'. Create a costume parameter and then do your replace command. Hope this helps.

Get-ChildItem | Get-Content -Delimiter "~" | foreach { $_ -replace "`r|`n","" }
like image 32
PapaJim10 Avatar answered Oct 05 '22 22:10

PapaJim10