3 ms·
By formatting I was referring to the fact that he had to match the 6th field. If grep would return 100k and only 10 in the desired field awk is obviously handy
by brent 19y ago
By formatting I was referring to the fact that he had to match the 6th field. If grep would return 100k and only 10 in the desired field awk is obviously handy (the exception). In the general case where you are just trying to hunt things down who stops and counts which field their target string is in. I could have run grep and analyzed the results by the time you count to the right field. If you miscounted however... how do you know?
- ralph 19y agoThe example was using awk to pick "Dec" out in the month column whilst pointing out a grep for "Dec" would also match the filename "December" which didn't have "Dec" in the month column. awk's clearly better than grep in this case. It's not hard to count the column and you can always do a ... | awk '{print $6}' | sort | uniq -c to see if you've got it right. In fact, a common way to develope the pipeline for a one-off task is to keep appending a pipe and another command to the previous pipeline command. That way, you can see a sample of what's being produced instead of imagining it. You couldn't have analysed the results of grep, discarding the non-month matches of "Dec" in the time taken to count up to field 6 if the number of lines was at all significant. Don't be silly. If I did miscount and no lines matched I may be suspicious and look more closely. If some lines matched but on a different column than intended I may notice. I can re-run the command after correction or try the {print $6} idea. How would you notice if your manual* analysis failed to spot the extra result from grep here and there. Would you do your manual analysis twice? Ask someone else to do it too? Or just think "good enough" and use the data for the next stage?