Count occurrences of character per line/field on Unix

后端 未结 10 2108
难免孤独
难免孤独 2020-12-23 16:19

Given a file with data like this (ie stores.dat file)

sid|storeNo|latitude|longitude
2tt|1|-28.0372000t0|153.42921670
9|2t|-33tt.85t09t0000|15t1.03274200
         


        
10条回答
  •  轮回少年
    2020-12-23 17:05

    cat stores.dat | awk 'BEGIN {FS = "|"}; {print $1}' |  awk 'BEGIN {FS = "\t"}; {print NF}'
    

    Where $1 would be a column number you want to count.

提交回复
热议问题