有一个比较好的在线正则测试:http://tool.oschina.net/regex/
回到正题,假设一段信息如下:
inet addr:192.168.1.100Bcast:192.168.1.255Mask:255.255.255.0 addr:
运用正则效果如下:
^.*addr:
#!/bin/ksh
echo "$@"
执行 :a.sh 1 2 3 4
1 2 3 4
${paramter-word} 会被替换成变量 parameter 的值,如果 parameter 不存在,则被替换成 word。所以
${@-'-i'} 就会被替换成脚本的输入参数 ,但是如果脚本没有输入参数,则替换成 -i
ip=`(adb devices|sed -n '2,$p'|awk '{print $1}')`
ipNum=$((${#ip[@]}-1))
${#fileinfo[@]} 是取的fileinfo这个数组的个数
-------------------------------------------------
-------------------------------------------------
示例一、
192.168.11.54:5555 device
脚本:
ip=(`adb devices|sed -n '2,$p'|awk '{print $1}'`)
devices=(`adb devices|sed -n '2,$p'|awk '{print $2}'`)
echo the ipnum is : $ipnum
echo The ip is : $ip
echo The aite is: ${#ip[@]}
echo The aite-1 is: $((${#ip[@]}-1))
echo The daole2 is: $2
the ipnum is : 0
The ip is : 192.168.11.54:5555
The aite is: 1
The aite-1 is: 0
The daole2 is:
-------------------------------------------------
.+ :表示后续的一个字符或者一段字符
-------------------------------------------------
[^] 和 [\t \T] :代表所有字符
数字取反
| sed -e 's/[^0-9A-Z]//g'
批量代码:alias tree='find . -print | sed -e '\''s;[^/]*/;|____;g;s;____|; |;g'\'''
显示tree数列
find . -print | sed -e 's;[^/]*/;|____;g'
.
|____培训文档
|____|____.DS_Store
sed -e 's;[^/]*/;|____;g;s;____|; |;g'
.
|____培训文档
| |____.DS_Store
| |____问题描述与状态迁移.pages