兩個文件求和,按照某咧html
awk 'NR==FNR{a[$1]=$2;next}NR>FNR{if($1 in a) a[$1]+=$2 }END{for(x in a)print x"\t"a[x]}' 1.txt 2.txtshell
awk 'NR==FNR{a[$1]=$2;next}NR>FNR{if($1 in a) b[$1]=a[$1]+$2 }END{for(x in b)print x"\t"b[x]}' 1.txt 2.txt數組
array=(bill chen bai hu);bash
num=${#array[@]} //獲取數組元素的個數。工具
ps aux |grep -v USER | sort -nk +4 | tail 按照內存使用大小排序spa
find com -name *.class | xargs grep 'FetchRMRBTemplate' 遍歷一個目錄下的全部文件找關鍵字調試
find . -name "*.xml" | xargs wc -l 統計每一個文件,和全部文件的和的總行數code
具體使用方法:首先使用set -x開啓調試模式,最後使用命令set +x關閉調試模式。xml
[root@localhost shell]# cat hello.sh #!/bin/bash # This is a test script. # 2013/12/20#使用set命令的選項x,啓動調試模式set -x NAME=Jhon
echo $NAME
echo "Hello,$NAME"#使用+x表示關閉調試模式set +x
[root@localhost shell]# ./hello.sh+ NAME=Jhon+ echo Jhon Jhon+ echo Hello,Jhon Hello,Jhon+ set +x
awk '{sum=sum+$3} END {print sum}' 1.log 第三列的和htm
comm -3 <(sort 3.log|uniq ) <(sort 2.log|uniq ) | sed 's/^\t//' 差集
comm -12 <(sort 3.log|uniq ) <(sort 2.log|uniq ) | sed 's/^\t//' 交集
grep -F -f 2.log 3.log 交集
grep -F -f -v 2.log 3.log 差集
cat s.txt | sed -e '/^$/d' >> s.0.txt 去掉文件的空行
sed -n '2, 10!p' input //表示打印出非2--10行的行
sed:-i:與-e的區別在於:當使用-e時,sed執行指令並不會修改原輸入文件的內容,只會顯示在bash中,而使用-i選項時,sed執行的指令會直接修改原輸入文件。
刪除:d命令
$ sed '2d' example-----刪除example文件的第二行。
$ sed '2,$d' example-----刪除example文件的第二行到末尾全部行。
$ sed '$d' example-----刪除example文件的最後一行。
$ sed '/test/'d example-----刪除example文件全部包含test的行。
sed 's/w/a/g' s.txt 文件中的 w 替換問a