Replace ^ M with <space> in all lines of the file

I have a log file with embedded ^ M. I would like to replace ^ M with one space.
I tried options on this:

(Get-Content C:\temp\send.log) | Foreach-Object {$_ -replace "^M", ' '} | Set-Content C:\temp\send.out  

The output file contains a new line, where each ^ M was, not at all what I was looking for ...
The problem I'm trying to solve includes studying the last lines of the $ cnt file:

$new = Get-Content $fn | Select-Object -Last $cnt;
$new

When I display $ new, ^ M is interpreted as CR / LF.
How can I remove / replace ^ M? Thanks for any pointers ....

+3
source share
3 answers

, ^ M -replace, , replace M (^). ^ M .

, (^ M) :

(Get-Content C:\temp\send.log) | 
    Foreach-Object {$_ -replace "`r", ' '} | 
    Set-Content C:\temp\send.out

$new = Get-Content $fn | Select-Object -Last $cnt;
$new.replace("`r"," ")
0

, ^? $count , -Tail Get-Content. , ^ M , -creplace -replace.

Get-Content $inputfile -Tail $count | ForEach-Object { $_ -creplace '\^m',' ' } | Set-Content $outputfile
0

, , .

:

$new = Get-Content $fn | Select-Object -Last $cnt;
$new
$new.gettype()
$new[0].gettype()

, , $new - , $new [0] - . , $new [0] CR, LF CRLF - . , $new , ($ new [0], $new [1]...) CRLF, .

, CR CRLF . CRLF, , .

, .

0

All Articles