convert txt utf-8 to ansi - PowerShell - Spiceworks Community
文章推薦指數: 80 %
I have a system generation csv files but as UTF-8. I want a way to automatically convert the files in ANSI for use in a different system.
Home
News&Insights
News&InsightsHome
Innovation
ITCareers&Skills
Cloud
CyberSecurity
FutureofWork
AllCategories
Marketing
HR
Finance
Community
Askquestion
CommunityHome
SpiceworksOriginals
Cloud
Collaboration
Networking
WaterCooler
Windows
Allforums
How-Tos
Scripts
Vendors
Meetups
Reviews
OnlineEvents
Login
Join
Login
Join
Home
Programming
PowerShell
converttxtutf-8toansi
Postedbydidierodayo
Solved
PowerShell
IhaveasystemgenerationcsvfilesbutasUTF-8.IwantawaytoautomaticallyconvertthefilesinANSIforuseinadifferentsystem.anywaytoschedulethisusingwindowstaskandpowershellorbatfile?Source: C:\tempDestination:C:\convertedFilename:namesexport
Spice(2)
Reply(2)
flagReport
didierodayo
Thispersonisaverifiedprofessional.
Verifyyouraccount
toenableITpeerstoseethatyouareaprofessional.
anaheim
check
BestAnswer
francishagyard2
Thispersonisaverifiedprofessional.
Verifyyouraccount
toenableITpeerstoseethatyouareaprofessional.
thaipepper
PowerShellExpert
check
195
BestAnswers
thumb_up
347
HelpfulVotes
checkBestAnswer
I'mafraidyou'llhavetobemorespecificaboutwhichsystemyouwanttousethefileon,asANSIencodingdoesn'treallyexistitjustreferstothedefaultcodepageoftheOS(read:here)AsanexampleforASCIIyoucandoitlikethis:
Powershell
Get-Content-Path"C:\Temp\SourceFile.txt"|Out-File-FilePath"C:\Converted\DestFile.txt"-Encodingascii
Ifyouwanttoseeotheravailablechracterencodingoptionsusethis:
Powershell
Get-HelpOut-File-ParameterEncoding
Spice(4)
flagReport
2foundthishelpful
thumb_up
thumb_down
ViewBestAnswerinrepliesbelow
2Replies
francishagyard2
Thispersonisaverifiedprofessional.
Verifyyouraccount
toenableITpeerstoseethatyouareaprofessional.
thaipepper
PowerShellExpert
check
195
BestAnswers
thumb_up
347
HelpfulVotes
checkBestAnswer
I'mafraidyou'llhavetobemorespecificaboutwhichsystemyouwanttousethefileon,asANSIencodingdoesn'treallyexistitjustreferstothedefaultcodepageoftheOS(read:here)AsanexampleforASCIIyoucandoitlikethis:
Powershell
Get-Content-Path"C:\Temp\SourceFile.txt"|Out-File-FilePath"C:\Converted\DestFile.txt"-Encodingascii
Ifyouwanttoseeotheravailablechracterencodingoptionsusethis:
Powershell
Get-HelpOut-File-ParameterEncoding
Spice(4)
flagReport
2foundthishelpful
thumb_up
thumb_down
user930587
Newcontributor
pimiento
Get-ContentmightbenotoptimalforconvertingtexttoUTF-8asithandles
theinputfilelinebylineandmaycausechangingthelineending(for
example,ifyoumovetextfilesbetweenUnixandWindowssystems).Duetothis
behavior,Get-Contentisnotthebestchoiceaswell,ifperformance
matters. Youcansolvethisproblemby
usingtheRAWswitchwithGet-Contentasdescribedinthenextsection.
Orevenmoresimply,usetheRawswitchasdescribedheretoavoidthat
overheadandreadthetextinasingleblock:
Get-Content$inFile-Raw
Get-ContentC:\fso\MyFile.txt-Raw
Usingthe–RawparameterwithGet-Contentforces
WindowsPowerShelltoignorenewlinecharactersandend-of-linereturns,and
instead,returnthecontentsofthefileasonestring.
CorrectedCommand:
Get-Content
延伸文章資訊
- 1convert txt utf-8 to ansi - PowerShell - Spiceworks Community
I have a system generation csv files but as UTF-8. I want a way to automatically convert the file...
- 2File encoding - Mastering Windows PowerShell Scripting
File encoding Windows editors, including ISE, tend to save files using what is commonly known as ...
- 3How to save command output to file using Command Prompt or ...
- 4How to convert multiple files encoded in UTF-8-BOM to ANSI?
I would like the output to be correct in both cases. If Powershell it's not the solution, what el...
- 5Convert text file to ANSI format - powershell - Stack Overflow
The following solved my problem: Out-File 'file.txt' -Append -Encoding Ascii. This enabled me to ...