5

awk - count character count of fields

view full story
linux-howto

http://www.unix.com – Hello All, I got a requirement when I was working with a file. Say the file has unloads of data from a table in the form Code: 1|121|asda|434|thesi|2012|05|24| 1|343|unit|09|best|2012|11|5| I was put into a scenario where I need the field count in all the lines in that file. It was simply achieved by Code: awk -F"|" '{print NF}' file Now the case is, I need the count of characters in a field. For example, Code: head -2 file | awk -F"|" '{do something}' Output should be, Code: 1-3-4-3-5-4-2-2 1-3-4-2-4-4-2-1 Thanks :) Mode (HowTos)