Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 1
    The -o option for grep is not POSIX. What OS are you on? Commented Nov 11, 2013 at 15:24
  • @jordanm I'm on ubuntu, however I'm helping out a friend who is using windows with the utils from msysgit that his company has preinstalled. Commented Nov 11, 2013 at 15:51
  • 1
    Just so you know, your grep command wouldn't have worked anyway, you should specify \t as $'\t' but anyway, wc -l would give you the total number for the whole file, not for each line. I can't find a way of getting info per line without a minimum of awk/bash/perl etc. Commented Nov 11, 2013 at 16:31
  • 1
    Best way to help your friend is probably not "Here's a nickel, kid. Get yourself a better computer" but if they're going to insist on crippling their toolkit it's the only accurate one. awk 'BEGIN{FS="\t"} NR==1{f=NF} f!=NF { print "tab mismatch at line "NR; exit 1; }' Commented Nov 11, 2013 at 16:37
  • 1
    @naxa it didn't :). Try counting manually, '\t' will count the number of t letters and anyway, wc -l will print the number of lines in total, so in this case, the total number of ts in the file, not the number per line. Try printf 'foo\tbar' | grep -o '\t' | wc and then printf 'foo\tbar' | grep -o $'\t' | wc. Commented Nov 11, 2013 at 16:55