Convert text file to ANSI format - powershell - Stack Overflow
文章推薦指數: 80 %
The following solved my problem: Out-File 'file.txt' -Append -Encoding Ascii. This enabled me to save the file in ANSI format. Home Public Questions Tags Users Companies Collectives ExploreCollectives Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Collectives™onStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. LearnmoreaboutCollectives Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. LearnmoreaboutTeams ConverttextfiletoANSIformat AskQuestion Asked 5years,2monthsago Modified 2years,5monthsago Viewed 24ktimes 1 IamrunningtwoPowershellscripts.OnePowershellscriptaddsthehostnametoatextfile.OtherPowershellscriptappendstheipaddressofthemachinetothesamefile. So,the.txtfilelooksasfollows: hostname ipaddress But,thisfileisbeingsavedinUnicodeformatbydefault.WhatcanIdosothat,thetextfileisstoredinANSIformat? Iuse PowerShellv2.0. [System.Text.Encoding]::Default IsSingleByte:True BodyName:iso-8859-1 EncodingName:WesternEuropean(Windows) HeaderName:Windows-1252 WebName:Windows-1252 WindowsCodePage:1252 IsBrowserDisplay:True IsBrowserSave:True IsMailNewsDisplay:True IsMailNewsSave:True EncoderFallback:System.Text.InternalEncoderBestFitFallback DecoderFallback:System.Text.InternalDecoderBestFitFallback IsReadOnly:True CodePage:1252 powershelltextunicodeencodingansi Share Improvethisquestion Follow editedOct14,2017at19:33 glennsl 26.6k1212goldbadges5858silverbadges7272bronzebadges askedJul25,2017at14:20 MistletoeMistletoe 34722goldbadges44silverbadges1313bronzebadges 1 1 WhatPowerShellversiondoyouuse?Whatdoes[System.Text.Encoding]::Defaultreturn?Howdoyouwritetothefile? – user6811411 Jul25,2017at14:39 Addacomment | 2Answers 2 Sortedby: Resettodefault Highestscore(default) Trending(recentvotescountmore) Datemodified(newestfirst) Datecreated(oldestfirst) 6 Dependingonhowyouareoutputtingyourtextyoumayneedtosettheencodingtype.UsingOut-File-EncodingyouusethetypeofASCII.ThisalsodependsontheversionofPowershellyou'reusing. See:SS64Out-FileandSettheencodingtoANSIinPowerShell2.0 Share Improvethisanswer Follow editedJul25,2017at14:29 MathiasR.Jessen 143k1111goldbadges135135silverbadges186186bronzebadges answeredJul25,2017at14:24 JasonSnellJasonSnell 1,3951313silverbadges2121bronzebadges 0 Addacomment | 2 Thefollowingsolvedmyproblem: Out-File'file.txt'-Append-EncodingAscii ThisenabledmetosavethefileinANSIformat. Share Improvethisanswer Follow answeredJul25,2017at15:10 MistletoeMistletoe 34722goldbadges44silverbadges1313bronzebadges Addacomment | YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedpowershelltextunicodeencodingansioraskyourownquestion. TheOverflowBlog HowtoearnamillionreputationonStackOverflow:beofservicetoothers Therightwaytojobhop(Ep.495) FeaturedonMeta BookmarkshaveevolvedintoSaves Inboximprovements:markingnotificationsasread/unread,andafiltered... Revieweroverboard!Orarequesttoimprovetheonboardingguidancefornew... CollectivesUpdate:RecognizedMembers,Articles,andGitLab Shouldweburninatethe[script]tag? Linked 3 SettheencodingtoANSIinPowerShell2.0 Related 597 Bestwaytoconverttextfilesbetweencharactersets? 387 Unicode,UTF,ASCII,ANSIformatdifferences 258 WhatisANSIformat? 891 MySQL:LargeVARCHARvs.TEXT? 846 Printstringtotextfile 30 PowerShellout-file:preventencodingchanges 6921 Howtofindallfilescontainingspecifictext(string)onLinux? 0 CannotwriteChineseCharacterstoANSIfilesviaCStdioFile? HotNetworkQuestions Unknownnotation:squarebrackets,triangles,andnumbers IfthedrowshadowbladeusesShadowSwordasarangedattack,doesitthrowasword(thatitthenhastoretrievebeforeusingitagain)? DotheseresultsmeanthatIhavefoundthisexoplanet? AmIreallyrequiredtosetupanInheritedIRA? Whatisthedefinitionofatrollinthelegalcontext? Determinethelengthoftherestofamathdisplaylineformultlined Wouldatraitthat'sgeneticshave"circulardominance"beplausible? My(large)employerhasn'tregisteredanobviousmisspellingoftheirprimarydomainURL Canyoufindit? Howdoyoucalculatethetimeuntilthesteady-stateofadrug? WhydoNorthandSouthAmericancountriesoffercitizenshipbasedonunrestrictedJusSoli(rightofsoil)? Workplaceidiomfor"beiGelegenheit"-ordertodoeventually,butdonotprovidepriority InD&D3.5,whathappenswhenyouplopaheadbandofintellectonananimal? Canananimalfilealawsuitonitsownbehalf? Isitokaytore-renderaplotusedinanotherpublication? Whydoesthesameelectrontransitionreleasephotonsofdifferentfrequenciesforsomeelements? StrangeFruitfromTomatoPlant FPGAlogicthreshold-distinguishingalogic0and1 WhathappenswhenthequasarremnantsreachEarthin3millionyears? Howcanmyaliensymbiotesidentifyeachother? HowdothosewhoholdtoaliteralinterpretationofthefloodaccountrespondtothecriticismthatNoahbuildingthearkwouldbeunfeasible? Whyarefighterjetssoloudwhendoingslowflight? Interpretinganegativeself-evaluationofahighperformer ArethereanyspellsotherthanWishthatcanlocateanobjectthroughleadshielding? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. default Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings
延伸文章資訊
- 1Thomson Data Analyzer - Save as ANSI Workaround (TDAv3.01)
- 2How 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...
- 3File encoding - Mastering Windows PowerShell Scripting
File encoding Windows editors, including ISE, tend to save files using what is commonly known as ...
- 4PowerShell 輸出結果編碼問題 - 黑暗執行緒
Do-Something.ps1 > output.txt 存檔是用ANSI/BIG5 編碼,但事實不然。 ... 其編碼Export-PSSession 用UTF8(含BOM) New-Ite...
- 5How to save command output to file using Command Prompt or ...