1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| #点赞人数统计 a=$(curl -s https://testerhome.com/topics|grep -o 'href="/topics/[0-9]*"'|awk -F '/|"' '{print $4}');for id in $a;do url='https://testerhome.com/topics/'$id;zan=$(curl -s $url|grep -o -m1 '<span>[0-9]*'|awk -F '>' '{print $2}');if [ -n "$zan" ];then echo $url '点赞人数' $zan;else echo $url '点赞人数' 0;fi;done|awk -F '/' '{print $NF}'
echo -e "1|2|3\n4|5|6\n7|8|9"|awk -F '|' 'BEGIN{a=0}{a=a+$2}END{print a}'
curl -s https://www.baidu.com/ |grep href |grep -o "http[^>]*" | while read line;do curl -s -I $line | grep 200 &>/dev/null && echo 200 $line || echo ERR $line;done
curl https://testerhome.com/api/v3/topics.json 2>/dev/null | sed 's/"title":"[^"]*/title":"xxxxxx"/g'
#统计nginx日志访问量最高 awk {'print $7'} nginx.log |awk -F '?' '{print $1}' |sort |uniq -c |sort -n |tail -1 |awk '{print $2}' #平均耗时 awk {'print $7,$(NF-1)'} nginx.log | grep '^/api/[a-z0-9_]*' |awk '{s+=$2} END{print s/NR}'
awk '$7~/api\/[a-z]+$/{sum+=$(NF-1)}END{print sum/NR}' nginx.log
seq 10|awk '/[5-9]/' seq 10|awk '/5/,/9/'
#分割 echo '1|2#3_4' | awk -F '#_|_|\\|' '{print $1}' echo '1|2#3_4' | awk 'BEGIN{FS="#|_|\\|"}{print $1}' #分割加分割符 echo '1|2#3_4' | awk 'BEGIN{FS="#|_|\\|";OFS="_"}{print $1,$2,$3,$4}' #分成多行 echo '1|2#3_4' | awk 'BEGIN{RS="#|_|\\|"}{print $1}' #分成多行拼成一行 echo '1|2#3_4' | awk 'BEGIN{RS="#|_|\\|";ORS="_"}{print $1}'
#awk格式化输出 awk 'BEGIN{printf "%.1f\n",1/3}' #求和 seq 10 2 20| awk '{sum+=$1}{print sum}' #求平均 seq 10 2 20| awk '{sum+=$1}{print sum/NR}' #输出大于14的 seq 10 2 20| awk '$1>14{data[NR]=$1}END{for(k in data)print data[k]}' #多点编辑(取出后两位) seq 125 137|sed -E 's#.(.)(.)#\1+\2#g'
#根据pid查看20秒内程序cpu,mem使用信息 for i in $(seq 1 20);do time=$(date +%H:%M:%S);cpu=$(ps -o %cpu -o %mem pid| tail -1);echo $time $cpu;sleep 1;done
#并发 while true; do count=$(jobs -l |grep Running | wc -l);[ $count -le 2 ] && { time curl https://www.baidu.com &>/dev/null & } || echo $count waiting;done
ps -o uname,pid,ppid,thcount,ni,pri,psr,pcpu,pmem,rss,vsz,sz,start_time,time,comm,command -e
#20秒内存平均 timeall=0; for i in $(seq 1 20);do time=$(date +%H:%M:%S);MEM=$(ps -o uname,pid,ppid,thcount,ni,pri,psr,pcpu,pmem,rss,vsz,sz,start_time,time,comm,command -p 9446 | awk -F ' *' '{print $9}' | tail -1);echo $time %MEM=$MEM ;timeall=$(awk 'BEGIN{print '$timeall'+'$MEM'}'); awk 'BEGIN{print '$timeall'/'$i'}' ;sleep 1;done
for i in $(seq 1 20);do time=$(date +%H:%M:%S);MEM=$(ps -o uname,pid,ppid,thcount,ni,pri,psr,pcpu,pmem,rss,vsz,sz,start_time,time,comm,command -p 9446 | awk -F ' *' '{print $9}' | tail -1);echo $time %MEM= $MEM ;sleep 1;done | awk '{print $0,t+=$3;print t/NR}'
for i in $(seq 1 20);do time=$(date +%H:%M:%S);MEM=$(ps -o uname,pid,ppid,thcount,ni,pri,psr,pcpu,pmem,rss,vsz,sz,start_time,time,comm,command -p 9446 | awk -F ' *' '{print $9}' | tail -1);echo $time %MEM= $MEM ;sleep 1;done | awk '{print $0;print (t+=$3)/NR}'
#打印cpu 内存 top -b -d 1 -n 20 -p 9446|grep --line-buffered 9446 | awk '{cpu+=$9;mem+=$10}{print $9,$10,cpu/NR,mem/NR}'
#图形化cpu mem top -b -d 1 -n 20 -p 9446|grep --line-buffered 9446 | awk '{cpu+=$9;mem+=$10}{print $9,$10,cpu/NR,mem/NR}'|gnuplot -e "set terminal dumb;plot '<cat' using 1 with line"
|