shell中+,*,[:space:]的用法
在linux中通常会使用shell结合正则表达式来过滤字符,本文将以一个简单的例子来说明+,*,[:space:]的一些用法+ 匹配1个或多个字符* 匹配0个或多个字符[:space:] 匹配空白字符,包括空格,tab文件file是含有多个空格和tab的几行字符,下面将以file文件为例做几个简单的实验[root@node1 ~]# cat file &...
shell中IFS用法
一 IFS的介绍 Shell 脚本中有个变量叫IFS(Internal FieldSeprator) ,内部域分隔符。完整定义是Theshell uses the value stored in IFS, which is the space, tab, and newline characters bydefault, to delimit words for the read and set commands, whenparsing output from command substitutio...
vim中替换和删除
1 替换 用空格替换以“#”开头的行:%s/^#.*//g2 删除空行 刪除没有内容的空行 :g/^$/d 刪除包含有空格组成的空行 :g/^\s*$/d 除以空格或tab开头到结尾的空行 :g/^[ |\t]*$/d 3 删除以“#”开头的行:g/^#.*/d...
sed,grep用法小结
1 打印关键字所在行及其后n行sed -n '/XX/,+np' filegrep "xx" -An yourfile2 获取关键字所在行和其上n行grep "xx" -Bn yourfile3 获取关键字所在行的行号sed -n '/pattern/=' file4 打印并标出行号grep -n file5 多关键字搜索grep -E "xxx|yyy" file6 |表示或关系,比如 'gd|good|dog' 表示有g...
shell获取字符串长度
方法一[root@192 ~]# str=123[root@192 ~]# echo ${#str}3方法二[root@192 ~]# str=123[root@192 ~]# echo $str|wc -L3
截取ip
方法一[root@192 andy]# ifconfig eth0|grep -w inet|cut -d " " -f 12|cut -d":" -f 2192.168.151.141方法二[root@192 andy]# ifconfig eth0|grep -w inet|cut -c 21-35192.168.151.141方法三[root@192 andy]# ifconfig eth0|grep -w "inet" |cut -d " " -f 12|sed's/^.*://g'192.168.151.141方法四[root@192 ...