老李分享:《Linux Shell脚本攻略》 要点(四)
2015-12-15 18:00
537 查看
老李分享:《Linux Shell脚本攻略》 要点(四)
1、IP地址的正则表达式: [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}2、grep用法//在多级目录中对文本进行递归检索[root@localhost program_test]# grep "yang" ./ -Rn./test.txt:6:laoyang./right.txt:1:1 yang man//忽略大小写匹配[root@localhost program_test]# echo hello world | grep -i "HELLO"
hello world//递归搜索所有.c和.cpp文件[root@localhost program_test]# grep "main()" . -r --include *.{c,cpp}
./hello.c:int main()
sin.c:int main()
hello.cpp:int main() //匹配某个结果之后的几行[root@localhost program_test]# echo -e "a\nb\nc\na\nb\nc"| grep a -A 1
a
b
--
a
b 3、cut命令cut,将文本按照列进行切割的小工具。//-d分界符; -f要提取的列[root@localhost program_test]# cut -d ":" -f5 --complement passwd_yang
root:x:0:0:/root:/bin/bash
bin:x:1:1:/bin:/sbin/nologin [root@localhost program_test]# cut -c1-5 passwd_yang
root:
bin:x
daemo
adm:x //统计特定文件中的词频[root@localhost program_test]# cat word_freq.sh#!/bin/bash if [ $# -ne 1 ];thenecho "Usage: $0 filename"exit -1fi filename=$1 egrep -o "\b[[:alpha:]]+\b" $filename | \awk '{ count[$0]++ } \END { printf("%-14s%s\n","word","Count");\for(ind in count) \{ printf("%-14s%d\n",ind,count[ind]); } }'4、sed命令(stream editor 流编辑器)适用文本处理.//1.替换,从第3个开始替换[root@localhost program_test]# echo this thisthisthis | sed 's/this/THIS/3g'
this thisTHISTHIS//2.删掉空白行[root@localhost program_test]# sed '/^$/d' choice.sh //3.已匹配的字符串标记&[root@localhost program_test]# echo this is an example | sed 's/\w\+/[&]/g'
[this] [is] [an] [example] //4.替换举例.[root@localhost program_test]# cat sed_data.txt
11 abc 111 this 9 file contains 111 11 88 numbers 0000
[root@localhost program_test]# cat sed_data.txt | sed 's/\b[0-9]\{3\}\b/NUMBER3/g'
11 abc NUMBER3 this 9 file contains NUMBER3 11 88 numbers 0000
相关文章推荐
- 老李性能测试分享
- 你想不到:咖啡馆里上工具课
- 移动端自动化测试开课了
- 老李分享:什么是好战略
- 性能调优案例分享:Mysql的cpu过高
- 性能测试分享:性能测试工具开发的案例分享(上)
- 性能测试分享:性能测试工具开发的案例分享(下)
- 性能测试培训:批量执行Jmeter脚本之ant调用 2
- 性能测试培训:分布式测试之jmeter1
- 老李案例分享:MAT分析应用程序服务出现内存溢出过程1
- 老李案例分享:MAT分析应用程序服务出现内存溢出过程2
- 老李案例分享:定位JAVA内存溢出 1
- 老李案例分享:定位JAVA内存溢出 2
- 性能测试培训: 建立压力模型
- 老李分享:你知道有哪些持续集成工具
- 老李分享知识:性能测试之TPS和吞吐率
- 老李分享知识:性能测试之吞吐量
- 性能测试培训:分析内训泄露的案例
- 自动化测试培训:qtp脚本获取获取汇率数据
- 性能测试培训:sql server性能测试分析局部变量的性能影响1