平时也经常会用到awk, grep一类的,今天看到有个小总结,就记录一下。
原址如下:
http://space.itpub.net/519536/viewspace-557309
作为一位DBA,不熟练的掌握Shell是万万不可的,简单列一些常用的Shell命令的用法。
awk '/[Gg]reen/' file
awk '$1 ~/^…a/' file
awk '$0 ~/(Green|green)/' file #等价于egrep "Green|green" file
awk '{print $1}' file | tee file2
awk '{if ($4 ~/Brown/) print $0}' file
awk '{if ($4 !~/Brown/) print $0}' file
awk '{if($1=="条件1" && $4=="条件2") print $0}' file
awk '{if($1=="条件1" || $4=="条件2") print $0}' file
awk '{print length}' file
awk 'BEGIN {print "this is a title"} {print $1} END{print "the end"}' read.txt
awk 'END {print NR}' file #等价于wc –l file
awk 'END {print NF}' file
awk 'END {print FILENAME}' file
sed –n '/e\{2\}/'p file1
sed –n '/e\{2,\}/'p file1
sed –n '/e\{2,3\}/'p file1
sed 's/Tony/Terry/'g file1
grep –w "精确匹配条件" file
grep –i "匹配字符串" file
grep –v "匹配字符串" file
grep –E "条件1|条件2" file
grep [^字符串] file
find . –name "*.sh" | xargs grep expr
find ~ –mtime 2
find / –size 0c
find ~/app –type d #列出根目录下的app目录中所包含的所有文件夹
sort +4n file1
sort –u file
-- The End --