shell学习笔记[grep,sed,awk,sort,for,until,while]

1.grep常用做查找,sed常用做替换,awk常用做切割后格式化输出
例:
tail -50  lighttpd.accesslog |grep ".flv"|awk '{print $7}'|sed 's///f//1////g'|sed 's//.flv//g'
数据:
222.73.161.121 - - [21/May/2009:10:21:41 +0800] "GET /f/1/fe99b0e436e97fabda26d95f6b44ab719494518.flv HTTP/1.0" 200 747 "http://tieba.baidu.com/f?kz=301511794" "Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.0)" 0
222.73.161.122 - - [21/May/2009:10:19:19 +0800] "GET /f/1/fe99b0e436e97fabda26d95f6b44ab719494518.flv HTTP/1.0" 200 747 "http://tieba.baidu.com/f?kz=301511794" "Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.0)" 0
输出:
fe99b0e436e97fabda26d95f6b44ab719494518
fe99b0e436e97fabda26d95f6b44ab719494518

例:
tail -50 access.log|grep ".flv"|awk '{print $7}'|sed 's/.*//f//1//./{3/}//g'|sed 's//.flv.*//g'
或者
tail -50 access.log|grep ".flv"|awk '{print $7}'|awk -F/ '{print $6}'|awk -F. '{print $1}'|sed 's/./{3/}//g'

数据:
124.166.10.152 - - [11/Aug/2009:18:42:25 +0800] "GET http://d164.v.iask.com:80/f/1/6b6cd078d4cee31064532cb261d94a2e19709794.flv HTTP/1.1" 200 105974 "http://p.you.video.xxx.com.cn/player/outer_player.swf?auto=1&vid=22862499&uid=1626906254" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2; MAXTHON 2.0)" TCP_HIT:NONE 468
123.116.5.36 - - [11/Aug/2009:18:42:25 +0800] "GET http://tj6.dhot.v.iask.com:80/f/1/5d2749884ca72b50c7c7fa74bbade9c519640957.flv?vstr=8fc217f6c4f11d6a5f12c921b2fbc303 HTTP/1.1" 200 10814116 "http://p.you.video.xxx.com.cn/swf/BokerPlayerV3_1_1_090804.swf" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)" TCP_MEM_HIT:NONE 34945
输出:
cd078d4cee31064532cb261d94a2e19709794
749884ca72b50c7c7fa74bbade9c519640957
2.
sort -b正序
sort -r反序
3.
我的登录用户是chang
以下都是测试成功运行的单行命令
until who|grep chang ;do  echo "x" ;done;
for loop in `cat text.txt` ; do echo $loop ; done;
for loop in `ls` ; do `rm -rf $loop.txt` ; done;
i=0;while [ $i -lt 10 ] ;do echo $i;i=`expr $i + 1`; done;

i=0;while [ $i -lt 3000 ] ;do `mkdir $i`;i=`expr $i + 1`; done;

4.awk 使用正则

ifconfig|awk '{if($0 ~ /114/ && $0 !~ /172\.16.*/) print $0}'


你可能感兴趣的:(linux,FreeBSD,shell)