SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Powershell : convert a file to UTF-8 without BOM + LF


Powershell : convert a file to UTF-8 without BOM + LF

Author
Message
Johan_1975
Johan_1975
SSC-Addicted
SSC-Addicted (479 reputation)SSC-Addicted (479 reputation)SSC-Addicted (479 reputation)SSC-Addicted (479 reputation)SSC-Addicted (479 reputation)SSC-Addicted (479 reputation)SSC-Addicted (479 reputation)SSC-Addicted (479 reputation)

Group: General Forum Members
Points: 479 Visits: 290
Hi,
I have an issue with files conversion in powershell.
1. I try a bcp command to export a file (with a format file for convenience), Format UTF8 + LF.
2. I convert it in UTF8 without BOM (but my LF begins CRLF)
3. I convert my CRLF to LF (but I lose my UTF8 without BOM conversion...)

Do you have any idea ?

Thanx a lot!!

The sourcecode :
# Creation Fichier BCP
$database = "Mydatabase"
$schema = "dbo"
$table = "t_TSCOM_Dashboard_hebdo"
$fichierBCP = "K:\saved\output\t_TSCOM_Dashboard_hebdo.bcp"
$fichierFormat = "K:\saved\FORMAT\t_TSCOM_Dashboard_hebdo_6.fmt"
$loginUser = "MeMyAndMyself"
$passwordUser = "XXXXXXXXXXXXX"
$server = "MyServer"

$bcp = "bcp $($database).$($schema).$($table) out $fichierBCP -f $fichierFormat -U $loginUser -P $passwordUser -S $server"
Invoke-Expression $bcp

## Affectation des fichiers
$fichierBCP_Contenu = Get-Content $fichierBCP
$fichierUTF8sansBOM = "K:\saved\output\MyFile_SLA_WEEK_HISTO_CRLF.DEL"
$fichierDEL = "K:\saved\output\MyFile_SLA_WEEK_HISTO.DEL"

## Conversion en UTF8 sans BOM (OK mais LF > CRLF)
[System.IO.File]::WriteAllLines($fichierUTF8sansBOM, $fichierBCP_Contenu)

## conversion CRLF > LF (mais on perd conversion UTF8-sansBOM)
(Get-Content $fichierUTF8sansBOM) -join "`n" | Out-File -Encoding UTF8 $fichierDEL


Johan Jezequel
** Sorry for my english, I promess you I do my best **

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search