AWK SED 与 LINUX常用命令

来源:互联网 发布:出租车叫车软件 编辑:程序博客网 时间:2024/06/05 15:00

awk的结构为: partten { action },逢每行都应用这个结构(可有多个这样的结构)

partten是条件,如 if (1 > 2) 或 BEGIN 或 END 或 1 > 2,action是执行动作,如print $1"\t"$2, 


sed的结构为:[start][,stop] command,逢每行都应用这个结构

startstop是用来决定是否在当前行应用command, star和stop可为数字,也可为正则匹配


正则表达式主要分为 字符表达重复次数表达,重复次数表达应用于前一个字符表达或()组

字符表达:普通字符 [] .

重复次精表达:* + ? {}

此外,还有 | 用来表示两组完整正则表达式的,()用来表示一个完整的正则表达式,还有$号用来引用被match的正则部分(perl)


AWK字典计算:

awk '{dict[$5]++} END {for(i in dict) print i,dict[i]}' failed.log2011-08-04 | sort -n -k 2 -r

AWK加和:

awk '{ SUM += $5} END { print SUM/1024/1024 }' 

AWK字符串切割:

awk '{split($0,a,":"); print a[3]}'

FIND:

find . -maxdepth 1 -mindepth 1 -not -name success.log2011-08-10 -not -name err.log2011-08-10 -not -name failed.log2011-08-10 -not -name crit.log -type f -exec mv {} /data/logs/logs-archive/cvm/ \;

SED替换:

sed "s/%//g" 把%替换成空


export IFS=","
for DISK in $DISKS ; do

...

done


原创粉丝点击