Count occurrences of character per line/field on Unix

后端 未结 10 2106
难免孤独
难免孤独 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 16:49

    You could also split the line or field with "t" and check the length of the resulting array - 1. Set the col variable to 0 for the line or 1 through 3 for columns:

    awk -F'|' -v col=0 -v OFS=$'\t' 'BEGIN {
        print "count", "lineNum"
    }{
        split($col, a, "t"); print length(a) - 1, NR
    }
    ' stores.dat
    

提交回复
热议问题