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
延伸文章資訊
- 1File encoding - Mastering Windows PowerShell Scripting
File encoding Windows editors, including ISE, tend to save files using what is commonly known as ...
- 2Out-File -encoding problems - TechNet - Microsoft
I have written one of my first PowerShell scripts to execute after I mirror my ... other than to ...
- 3ANSI Format - Micro Focus
- 4Thomson Data Analyzer - Save as ANSI Workaround (TDAv3.01)
- 5convert 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...