We are upgrading a process from FTP/PGP to SFTP (PUTTY/PSCP). The FTP
handles the Lf to CrLf conversion when in ASCII mode. However, for now,
there is only a BINARY mode with SFTP. I looked online and noticed several
"one-liners" in PERL to do this conversion. In PowerShell, how can I create
a file that has the correct CrLf terminator? I would likely use it in a SQL
Server 2005 job or SSIS package. I have not used PowerShell yet, but I am
willing to start.
Thanks,
Randy
PowerShell will detect LF as a newline when reading it, but doesn't
convert it implicitly.
Something like this should work:
(gc infile.txt) | %{$_.split("`n")} | Out-File outfile.txt
FOR /F "eol= delims= usebackq" %%a IN (%TARGET_RAW%) DO (
ECHO %%a>> %TARGET%
)
Set-Content always uses [Environment]::Newline, which basically means
that it generally uses "`r`n" ... to work around that, you need to set
it yourself.
To convert an "OldFile.txt" from (whatever) to [Environment]::Newline,
you could do:
Get-Content OldFile.txt | Set-Content NewFile.txt
To convert it and specify the line-terminator character:
Set-Content newfile.txt $(
[string]::Join( "`n", (Get-Content OldFile.txt))
--
Joel