How to display filename from a column using Awk?

后端 未结 3 1636
太阳男子
太阳男子 2021-01-22 12:22

I\'m trying to do a command which add to my file: Name of the current input file + Index of line where numbers of commas are less than 5 + numbers of commas across the line.

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-22 13:09

    FILENAME is a string, not a number. Use %s:

    awk -F"," '{ if(NF > 5) printf("Filename: %s  Index: %d Number of commas : %d\n",FILENAME,NR, NF-1); }' dsc* >> filename.csv
    

    From the section of man awk that discusses printf:

      %d, %i  A decimal number (the integer part).
    
      %s      A character string.
    

提交回复
热议问题