Converting text file to UTF-8 on Windows command prompt
文章推薦指數: 80 %
I need to convert a text file to utf-8 format via windows command prompt. You can easily do this with PowerShell: Get-Content . SuperUserisaquestionandanswersiteforcomputerenthusiastsandpowerusers.Itonlytakesaminutetosignup. Signuptojointhiscommunity Anybodycanaskaquestion Anybodycananswer Thebestanswersarevotedupandrisetothetop Home Public Questions Tags Users Companies Unanswered Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. LearnmoreaboutTeams ConvertingtextfiletoUTF-8onWindowscommandprompt AskQuestion Asked 5years,9monthsago Modified 2monthsago Viewed 130ktimes 27 IneedtoconvertatextfiletoUTF-8formatviaWindowscommandprompt.ThisneedstobedoneonanothermachineandIdonothaverightstoinstallsoftwareonthatmachine.Ineedsomethinglike: c:\notepadsource-filetarget-file--encodingoption IsthereaWindowscommandpromptutilitywhichcandoit? windowscommand-lineutf-8 Share Improvethisquestion Follow editedJan5,2017at14:38 KamilMaciorowski 62k2222goldbadges112112silverbadges166166bronzebadges askedJan5,2017at13:58 user1107888user1107888 37311goldbadge33silverbadges44bronzebadges Addacomment | 5Answers 5 Sortedby: Resettodefault Highestscore(default) Datemodified(newestfirst) Datecreated(oldestfirst) 44 Ineedtoconvertatextfiletoutf-8formatviawindowscommandprompt YoucaneasilydothiswithPowerShell: Get-Content.\test.txt|Set-Content-Encodingutf8test-utf8.txt FurtherReading Convertfrommostencodingstoutf8withpowershell Share Improvethisanswer Follow answeredJan5,2017at14:38 DavidPostill♦DavidPostill 146k7575goldbadges339339silverbadges374374bronzebadges 12 Additionally,youneedtoswitchtopowershellinordertoexecutethecommandandthenexitittogobacktowindowscommandprompt. – user1107888 Jan5,2017at16:09 1 @vibs2006UseaForEachloop.SeeForEach-PowerShell-SS64.com. – DavidPostill ♦ Jan28,2019at18:32 1 WillthismethodconverttoplainUTF-8orUTF-8-BOM? – CaleSweeney Oct23,2019at22:28 1 @JustMeSeemycommentabove-useaForEachloop – DavidPostill ♦ Aug1at16:51 1 @JustMeI'mnotgoingtodothatforyou. – DavidPostill ♦ Aug2at17:01 | Show7morecomments 5 UseiconvfromGNUWin32pack.Itismuchfaster,especiallyifyourfilesareaboutormorethan1Gb. "C:\ProgramFiles(x86)\GnuWin32\bin\iconv.exe"-fcp1251-tutf-8source.txt>result.txt Share Improvethisanswer Follow editedFeb21,2018at15:56 KamilMaciorowski 62k2222goldbadges112112silverbadges166166bronzebadges answeredFeb21,2018at15:09 RaulN-kRaulN-k 5111silverbadge11bronzebadge 3 1 whatdoesthecp1251flagdo? – lacostenycoder Mar11,2019at16:50 2 it'stheinputencoding.en.wikipedia.org/wiki/Windows-1251 – nadre May17,2019at8:57 1 Gitbashworksalso:iconv-fgb2312-tutf-8./s.txt>t.txt – ShawnXue May30,2020at4:47 Addacomment | 2 Hereisforeachconvert*.textfileto*.sqlfile: foreach($fileinget-ChildItem*.txt){ Echo$file.name Get-Content$file|Set-Content-Encodingutf8("$file.name"+".sql") } Share Improvethisanswer Follow answeredMay20,2019at10:20 nobjta_9x_tqnobjta_9x_tq 12122bronzebadges 1 afterrunsomesqlfile,sometimeerror,Idecidedtousinglinuxwithiconvcommand=)) – nobjta_9x_tq May28,2019at15:46 Addacomment | 1 Youcandothisfromthecommandpromptasfollows: powershell-command"Get-Content.\test.txt">test-utf8.txt Itturnsoutthatpipingtheoutputtoafilefromthecommandpromptsavesasutf-8. Share Improvethisanswer Follow answeredSep30,2020at20:49 GordHookerGordHooker 1111bronzebadge 1 butifIwanttoconvertmultiples.txtfiles,fromafolder+subfolders,whatisthecommand? – JustMe Aug1at14:15 Addacomment | 0 POWERSHELL:#AssumesWindowsPowerShell,use-Encodingutf8BOMwithPowerShellCore.Formultiplefiles: FIRSTSOLUTION: $files=Get-ChildItemc:\Folder1\-Filter*.txt foreach($filein$files){ Get-Content$file.FullName|Set-Content"E:\Temp\Destination\$($file.Name)"-Encodingutf8BOM } OR,SECONDSOLUTION(formultiplefiles): get-itemC:\Folder1*.*|foreach-object{get-content-Encodingutf8BOM$_|out-file("C:\Folder1"+$_.Name)-encodingdefault} OR,THETHIRDSOLUTION:(onlyfor2files) $a="C:/Folder1/TEST_ro.txt" $b="C:/Folder1/TEST_ro-2.txt" (Get-Content-path$a)|Set-Content-EncodingUTF8BOM-Path$b Share Improvethisanswer Follow answeredAug1at14:19 JustMeJustMe 75677silverbadges3030bronzebadges Addacomment | YourAnswer ThanksforcontributingananswertoSuperUser!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?Browseotherquestionstaggedwindowscommand-lineutf-8oraskyourownquestion. TheOverflowBlog HowtoearnamillionreputationonStackOverflow:beofservicetoothers Therightwaytojobhop(Ep.495) FeaturedonMeta BookmarkshaveevolvedintoSaves Inboximprovements:markingnotificationsasread/unread,andafiltered... Related 1 UnabletoconvertfiletoUTF-8 1 Printtextfilefromcommandlinewithoutshell"print"command 0 Convert.txt.filefromwindows-1251toutf-8 2 CreatenewfileinWinSCPwithUTF-8withoutBOMencoding 2 UTF-8FileisnotshowingChinesecharactersinExcel 1 InNotepad++theencodingofafileissettoUTF-8buttheencodingisactuallyASCII 2 ConvertatextfilefromansitoUTF-8inwindowsbatchscripting HotNetworkQuestions ElectronicCircuitsforSafeInitiationofPyrotechnics? WhyareRussiancombatantsinUkraineconsideredsoldiersratherthanterrorists? Howdoparty-listsystemsaccommodateindependentcandidates? HowradioactivecouldImakesomematerials,whilekeepingthem"cold"? Whataretheargumentsforrevengeandretribution? Probabilisticmethodsforundecidableproblem AmIreallyrequiredtosetupanInheritedIRA? Howtoremovetikznode? HowdoIdownloadmacOSMontereyonunsupportedMac? Unknownnotation:squarebrackets,triangles,andnumbers Canaphotonturnaprotonintoaneutron? Whatisthebestwaytocalculatetruepasswordentropyforhumancreatedpasswords? Sapiensdominabiturastris—isitnotPassivevoice? WhattestamItaking,anyways‽ Adecimal-basedunitoftime DoestheDemocraticPartyofficiallysupportrepealingtheSecondAmendment? Whyare"eat"and"drink"differentwordsinlanguages? Workplaceidiomfor"beiGelegenheit"-ordertodoeventually,butdonotprovidepriority InD&D3.5,whathappenswhenyouplopaheadbandofintellectonananimal? WherewasthisneonsignofadragondisplayedinLosAngelesinthe1990s?Isitstilltherenow? Traditionally,andcurrently,whatstopshumanvotecountersfromalteringballotstomakethem'Spoilt/Invalidvotes? Ifquasarsdestroyalllifeintheirhostgalaxy,thenhowdidlifesurvivewhenMilkyWaywasaQuasar6millionyearsago? InD&D3.5,canafamiliarbetemporarilydismissed? IsdocumentingabigprojectwithUMLDiagramsneeded,goodtohaveorevennotpossible? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings
延伸文章資訊
- 1How do I export command prompt results to text file?
Right click -> New -> Text Document. Open it, and do NOT type anything into it. Go to File -> Sav...
- 2Save text file in UTF-8 encoding using cmd.exe - Exchangetuts
How do I change the Encoding to UTF-8?
- 3Converting text file to UTF-8 on Windows command prompt
I need to convert a text file to utf-8 format via windows command prompt. You can easily do this ...
- 4windows - Save text file in UTF-8 encoding using cmd.exe
The default encoding for command prompt is Windows-1252. Change the code page (chcp command) to 6...
- 5雄::gsyan: Windows : 在cmd 下的dir 輸出UTF-8 編碼的清單
cmd /u /c :告訴cmd 以Unicode 格式輸出,並執行後面的兩道指令(粗體字的部份)。 · 以dir 將mp3 目錄中的檔名輸出到mp3_list.txt 中儲存(紅色的指令)。