Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

Shell 文字處理十大神器:find、grep、xargs、sort、uniq、tr、cut、paste、wc、sed、awk 核心用法速查

編輯:關於 Linux

Linux 文字處理核心工具箱,單行解決 90% 需求,複雜任務改用 Python。

精選範例

  • find:find . \( -name "*.txt" -o -name "*.pdf" \) -print、find . -regex ".*\(\.txt\|\.pdf\)$"、find . ! -name "*.txt"、find . -maxdepth 1 -type f、find . -type f -size +2k、find . -type f -perm 644、find . -user weber、find . -name "*.swp" -delete
  • grep:grep -r "pattern" .、grep -v "exclude"、grep -c "pattern" file、grep -n "pattern" file、grep -A2 -B2 "pattern" file
  • xargs:find . -name "*.log" -print0 | xargs -0 rm
  • sort/uniq:sort file | uniq -c | sort -nr 統計行頻率。
  • tr:tr 'a-z' 'A-Z' 大小寫轉換、tr -d '\r' 移除 DOS 換行。
  • cut:cut -d: -f1 /etc/passwd 取第一欄。
  • paste:paste file1 file2 合併欄位。
  • wc:wc -l file 計行數。
  • sed:sed 's/old/new/g' file、sed -n '10,20p' file 顯示 10-20 行。
  • awk:awk -F: '{print $1,$3}' /etc/passwd、awk '$3>1000' /etc/passwd 篩選 UID>1000。

熟練組合管道(|)即可完成強大資料轉換。

上一頁1234567下一頁共7頁

Copyright © Windows教程網 All Rights Reserved