Useful Commands/Text Processing: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 29: | Line 29: | ||
cat -n 3small.txt | cat -n 3small.txt | ||
</source> | </source> | ||
|- | |||
| Search Text || | |||
| grep 'Test' . | |||
|} | |} | ||
Revision as of 04:25, 10 September 2020
| 情境 | 指令 | |
|---|---|---|
| (改) 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' . |