Artificial intelligent assistant

Count the number of field by using AWK only and without other commands such as uniq Sample file wolf@linux:~$ awk // file.txt a b b c c d wolf@linux:~$ There are 2 fields, and 3 records in this example. wolf@linux:~$ awk '{print NF}' file.txt 2 2 2 wolf@linux:~$ To get a unique number, `uniq` command is used. wolf@linux:~$ awk '{print NF}' file.txt | uniq 2 wolf@linux:~$ Would it be possible to count the number of fields by using `awk` alone without `uniq` in this example? Desired Output wolf@linux:~$ awk <???> file.txt 2 wolf@linux:~$

It's slightly unclear what you want (since `uniq` will only remove _adjacent_ duplicates) however assuming you want to print all the unique field-counts across records _regardless of adjacency_ you could use


awk '!seen[NF]++ {print NF}' file.txt

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy c3633494494ef1e9f7b2d05394dd4a12