awk内置函数gsub
来源:互联网 发布:淘宝卖家怎么设置佣金 编辑:程序博客网 时间:2024/06/06 00:50
awk内置函数gsub
gsub():
gsub(r,s) 在整个$0中用s替代r;gsub(r,s,t) 在整个t中用s替代r
下面举个例子:
file
hello helloworld
hi hello
how are you
如果想让hello 被hi代替的话,可以利用下面的语句实现
awk ‘{gsub(“hello”,”hi”);print $0}’ file
[root@test1 home]# awk '{ gsub("hello","hi");print $0}' 4
hi hiworld
hi hi
how are you
此函数的另外的一个功能就是统计某个字符在一行中出现的次数
awk ‘{print gsub(“hello”,”any character”)}’ file
其中gsub中的两个参数第一个为我们要统计的单词,第二个为任意的一个字符即可。这样就统计出了hello 在每一行中出现的次数。
[root@test1 home]# awk '{print NR,gsub("hello"," ")}' file
1 2
2 1
3 0
gsub():
gsub(r,s) 在整个$0中用s替代r;gsub(r,s,t) 在整个t中用s替代r
下面举个例子:
file
hello helloworld
hi hello
how are you
如果想让hello 被hi代替的话,可以利用下面的语句实现
awk ‘{gsub(“hello”,”hi”);print $0}’ file
[root@test1 home]# awk '{ gsub("hello","hi");print $0}' 4
hi hiworld
hi hi
how are you
此函数的另外的一个功能就是统计某个字符在一行中出现的次数
awk ‘{print gsub(“hello”,”any character”)}’ file
其中gsub中的两个参数第一个为我们要统计的单词,第二个为任意的一个字符即可。这样就统计出了hello 在每一行中出现的次数。
[root@test1 home]# awk '{print NR,gsub("hello"," ")}' file
1 2
2 1
3 0
0 0
- awk内置函数gsub
- awk内置函数(split/substr/length/gsub)
- linux下awk内置函数(split/substr/length/gsub)
- @awk的gsub函数@
- awk中的gsub函数
- linux中awk下 gsub函数用法
- linux中awk下 gsub函数用法
- awk gsub 批量替换
- awk 字符串替换 gsub
- 在C中调用lua的内置函数string.gsub
- awk的内置函数
- **awk内置函数小节**
- #AWK#SUB内置函数
- awk内置字符串函数
- awk内置函数
- awk使用内置函数
- awk内置字符串函数
- awk内置函数
- instanceof的用法
- Android 点9图片
- PostgreSQL sql简单分页
- jquery 根据td中的checkebox元素该行所有td中的元素
- nyoj 7 街区最短路径问题【大水】
- awk内置函数gsub
- (Paper)使用LSH对Twitter做首报道检测(FSD)
- PHP在mac上面配置
- 关于spring mybatis 事务
- Java实现图片的上传以及下载 Tomcat服务器
- JAVA线程-JAVA同步
- Python距离包的实现
- js学习之math对象
- 概率论中基本概念回顾