Deleting Column Selection in AWK

后端 未结 1 486
余生分开走
余生分开走 2021-01-24 07:04

I\'d like to delete a selection of columns from a list of CSV files. The awk call is in-line as it is used in a shell script. I don\'t know beforehand how many columns the files

相关标签:
1条回答
  • 2021-01-24 07:32
    BEGIN {FS=",";
           split("1,2,3,4",dropers,",")
          }
    
    { split($0,row,FS);
      for(i in dropers) delete row[i]; 
      print NF "," length(row) "<<<";
      out=""; 
      print NF "," length(row) ">>>";
      for(i in row){print row[i] "lulu"; 
                    out = out "," row[i]}; 
      out = substr(out,2)
      sub(/[ \t]*$/,"",out);
      print out
    }
    

    with input:

    a,b,c,d,e,f,g
    

    prints:

    7,3<<<
    7,3>>>
    elulu
    flulu
    glulu
    e,f,g
    
    0 讨论(0)
提交回复
热议问题