dc
管理員

性別:男
來自:瓦肯星
發表總數:11722
註冊時間:2002-05-07 16:32 |
(第 3 篇) 【轉貼】powershell 字串處理與編碼方式
資料來源:IT 專業人員的技術資源
小弟在工作上需要應用powershell處理一些文字log,這些文字log的編碼格式是ANSI,當執行 Select-String -path d:\powershell_test\TEST.log -pattern "LogTest"這樣的命令來搜尋特定字串時,我發現powershell無法搜尋到需要的字串,必須把檔案轉成unicode編碼格式才能搜尋到正確字串,想請教各位高手先進 powershell是否有方法可以對ANSI格式的文字檔案直接進行搜尋字串動作?
找到一種替代的方式可以處理了,使用 gc -encoding string -path d:\powershell_test\TEST.log | select-string "LogTest" 這樣命令就可以直接處理ansi檔案格式,不用轉成unicode格式了,但在搜尋字串上Select-String 還是比較有效率,因此還請各位先進不吝賜教.
Your mind to my mind,
your thought to my thought |