awk或sed筛选文本部分数据


有下面一个log日志:

   
  912012091210203212   3487923(feixue11)  1500(3600)   15  2012-09-01 12:23:12
  
912012091010303456 8434662(woshini) 1000(2000) 10 2012-09-04 02:12:34
912012090910501233 7856091(sda3sd) 200(1200) 2 2012-09-07 12:11:46
912012090510604567 5621697(dsa4fg) 500(600) 5 2012-09-04 12:39:32

用awk或sed如何获取每行括号里的内容,然后输入到一个新文件里,上面log格式每隔字段以tab分隔

sed shell

detekoi 12 years ago

这样行不

   
  awk '{tmp2=substr($2,index($2,"(")+1);tmp3=substr($3,index($3,"(")+1);a[FNR]=substr(tmp2,0,length(tmp2)-1) "\t" substr(tmp3,0,length(tmp3)-1);print a[FNR]}' 1.txt
 

shirley answered 12 years ago

Your Answer