日期:2014-05-16  浏览次数:20665 次

Linux shell 常用

查找符合正则表达式的单词egrep -o "\b[[:alpha:]]+\b" m12.txt
合并文件:cat * > m.txt
uniq
sort

sed? stream editor
echo this THis this | sed 's:this:THIS:g'(global)
echo this THis this | sed 's:this:THIS:g'
sed -i '/^$/d' 1.txt
sed 's/ho*\+/[&]/g' 1.txt
echo s S | sed 's/\([a-z]\+\) \([A-Z]\+\)/\2 \1/'

awk? BEGIN PATTERN END? WHILE?? Pattern可以是正则表达式,条件以及匹配范围等
echo -e "line1\nline2" | awk 'BEGIN{print "start"} {print} END{ print "END" }'
echo -e "line1 f1 f2\nline2 f4 f5" | awk '{print "Line no:"NR "fileds:"NF} '
awk '{print $2"\t"$3}' 1.txt
awk 'END{print NR}' 1.txt
seq 5 | awk 'BEGIN{Sum=0;print "Summation"} {sum+=$0} END{print "=="sum}'
seq 5 | awk 'BEGIN{getline;print $1}
"command"|getline output
echo | awk '{"grep root /etc/passwd" | getline cmdout ; print cmdout }'
awk中的一些常用built-in函数
\b[0-9]\{3\}\b
\b[0-9]{3}\b