歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> 一行shell代碼搞定問題

一行shell代碼搞定問題

日期:2017/3/1 14:30:36   编辑:SHELL編程
一行shell代碼搞定問題 1. 查找至少有一行包含字符串mysql的xml文件,並按照出現次數降序排列 C代碼 find . -type f -iname "*.xMl"| xargs grep -c mysql | grep -v ":0$" | sort -t : -k 2 -nr C代碼 find . -type f -regex ".+xml" -exec grep -l mysql {} \; | xargs grep -c mysql | sort -t : -k 2 -nr 2. 統計第二列重復出現次數最多的5個字符串 C代碼 awk -F " # " '{print $2}' source.txt | sort | uniq -c | sort -nf | tail -n 5 > ~/PwdTop5.txt Java代碼 awk '{print $3}' source.txt | sort | uniq -c | sort -nr | head -5 > ./PwdTop5.txt & 3. 統計郵箱類型出現頻率最高的前5個 C代碼 awk -F " # " '{print $3}' source.txt | cut -d @ -f 2 | sort | uniq -c | sort -nf | tail -n 5 > EmailTop5.txt 注: source.txt 中的文本格式為 C代碼 AAA # BBB # [email protected] AAB # BBC # [email protected] AAC # BBD # [email protected] 4. 將所有txt文件的第一行輸出到first.txt文件中 C代碼 find / -name "*.txt" -exec head -n 1 {} \; 1>first.txt 2>/dev/null & 5. 查找當前路徑下最大的5個文件 C代碼 find . -type f -exec ls -l {} \; | sort -nr -k 5 | head -n 5 6. 統計所有jpg文件的大小 C代碼 find / -name "*.jpg" -exec wc -c {} \; | awk '{print $1}' | awk '{a+=$1} END{print a}' 7. 將PATH路徑下所有非jpg和JPG文件內容中的aaa部分重命名為bbb部分 C代碼 find $PATH -type f -print |grep -v ".*\.\(jpg\|JPG\)" | xargs sed -i "s/aaa/bbb/g"
Copyright © Linux教程網 All Rights Reserved