The first attempt, not very difficult:
gc .\tabfile.txt | % { ($_ -split "`t").Count - 1 }
Using the fact that when I split the string into tabs, I get an array with one more element than there are tabs in the string.
Another approach, avoiding line breaks:
gc .\tabfile.txt | % { ([char[]] $_ -eq "`t").Count }
Strings can be added to char[] (there is also a ToCharArray() method), then I use the fact that comparison operators work differently in collections, returning all matching elements instead of boolean ones. Thus, the comparison there returns an array containing all the tabs from the original string, from which I just need to get the number of elements.
source share