【vi】awk为指定行的指定字段添加一个单词
背景:每个php文件都有若干this->assert的行,这些行可能含有1个字段,可能含有多个字段;如果含有多个字段,则每个字段用,分割
要求:在最后一个字段的开头添加上$this->UrlMonitored
如下:
for i in `ls *php`;do cat $i | awk '{if(index($0,"this->assert")) {if(index($0,",")>0) { len=split($0,time, "," ); last=length(time[len]); print substr($0,0,length($0)-last)"$this->UrlMonitored""."time[len];}else print substr($0,0,length($0)-2)",$this->UrlMonitored);";}else{print $0}}' > ../case.bak/$i;ls ../case.bak/$i;done;