我想我能够模仿你用awk做的同样的事情.参考AWK手册:
原文链接:https://www.f2er.com/bash/384255.htmlhttp://www.staff.science.uu.nl/~oostr102/docs/nawk/nawk_92.html
这是我的文件的样子:
this,is,a,test,line this,line,with,the,second,field,blank this,another,blank,in,but,isnt,field
这是我跑的命令:
awk '{regex = "test"; where = match($0,regex); print "REGEX: ",where," on line ",NR}' test
并输出:
REGEX: 11 on line 1 REGEX: 10 on line 2 REGEX: 18 on line 3 REGEX: 0 on line 4
我做得很快又脏,但我希望它足以让你到达你需要的地方.