简体   繁体   中英

Counting only lines with words in them

How can I numerically count only lines that have words in them? In the example below, I have four lines with words in them:

100314:Status name one: 15
24 1 7 5 43 13 24 64 10 47 31 100 22 20 38 63 49 24 18 82 66 22 21 77 52 8 6 11 50 20 5 1 0 
101245:Status name two: 14
2 10 2 2 25 53 3 31 30 1 21 41 9 14 18 40 6 10 18 72 20 16 33 29 19 18 12 60 48 12 8 50 43 13
103765:Yet another name here: 29
45 29 29 475 63 69 47 94 65 65 69 55 53 905 117 57 42 92 90 59 91 52 79 101 192 87 144 74 115 82 78 109 12 96 64 78 111 106 84 19 0 7 
102983:Blah blah yada yada: 82
41 37 40 60 82 72 17 41 17 19 43 3

I've tried using different pipe combinations of wc -l and grep / uniq . I also tried counting only the odd lines (which works in the MWE above), but I'm looking for something more general-purpose for a large unstructured dataset.

It depends on how you define a word. If, for example, it's any two consecutive letters, you can just use something like:

grep -E '[a-zA-z]{2}' fileName | wc -l

You can simply adjust the regular expression depending on how you define a word (that one I've provided won't pick up "A" or "I" or "I'm" for example), but the concept will remain the same

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM