Shell正则表达式---待完善

有一个比较好的在线正则测试: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这个数组的个数


-------------------------------------------------

-------------------------------------------------

示例一、

List of devices attached
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




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值