Useful Commands/Text Processing: Difference between revisions

From Fundamental Ramen
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 1: Line 1:
{| class="wikitable"
{| class="wikitable"
! 情境 || 指令
! 🎯 Purpose || ⌨️ Command
|-
|-
| (改) BIG5 轉 UTF-8 || <syntaxhighlight lang="bash">iconv -f CP950 -t UTF-8 big5file.txt</syntaxhighlight>
| (改) BIG5 轉 UTF-8 || <syntaxhighlight lang="bash">iconv -f CP950 -t UTF-8 big5file.txt</syntaxhighlight>

Latest revision as of 02:00, 17 September 2026

🎯 Purpose ⌨️ Command
(改) BIG5 轉 UTF-8
iconv -f CP950 -t UTF-8 big5file.txt
(改) 搜尋 > 取代 > 存檔 - OSX/FreeBSD
# 取代後輸出 (測試與 pipe 用)
sed -e 's/搜尋RE/取代文字/' 檔名
# 取代後直接寫回檔案 (單檔自動化處理用)
sed -i -e 's/搜尋RE/取代文字/' 檔名
讀取超大文字檔的第一百萬行
(效能視 sed, awk 版本略有差異)
awk 'NR==1000000{print;exit}' 檔名
sed -n '1000000{p;q;}' 檔名
sed '1000000q;d' 檔名
讀取超大文字檔的其中幾行
awk 'NR>=1000000{print} NR==1000050{exit}' 檔名
輸出檔案並且顯示列號
nl 3small.txt
cat -n 3small.txt
Search Text
grep 'Test' .
apk search tcl | grep -e '^tcl'
pyenv install -l | grep -E '^\s+3'