我想我能够模仿你用awk做的同样的事情.参考AWK手册:
http://www.staff.science.uu.nl/~oostr102/docs/nawk/nawk_92.html
这是我的文件的样子:
this,is,a,test,line
this, ,a,test,line,with,the,second,field,blank
this, is,another,test,line,with,a,blank,in,the,second,field,but,the,field,isnt,blank
this, ,is,another,line,with,a,blank,second,field
Run Code Online (Sandbox Code Playgroud)
这是我跑的命令:
awk '{regex = "test"; where = match($0, regex); print "REGEX: ",where," on line ",NR}' test
Run Code Online (Sandbox Code Playgroud)
并输出:
REGEX: 11 on line 1
REGEX: 10 on line 2
REGEX: 18 on line 3
REGEX: 0 on line 4
Run Code Online (Sandbox Code Playgroud)
我做得很快又脏,但我希望它足以让你到达你需要的地方.
| 归档时间: |
|
| 查看次数: |
1452 次 |
| 最近记录: |