Convert text file to ANSI format - powershell - Stack Overflow

文章推薦指數: 80 %
投票人數:10人

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  



請為這篇文章評分?