- 论坛徽章:
- 769
|
本帖最后由 Herowinter 于 2014-05-26 13:38 编辑
回复 1# iocg
这是我写的代码,两个功能分开做是没问题的。- awk '{b[length($0)]++;total_lines++;for(i=1;i<=NF;i++){sub(/^\W+|\W+$/,"",$i);a[$i]++;total_words++}} END{print "Top 10 words frequency:";for(i in a)printf "%s %.2f%%(%d/%d)\n",i,100*a[i]/total_words,a[i],total_words| "sort -nr -k2 | head -10"}' i
- Top 10 words frequency:
- and 3.55%(23/647)
- to 3.40%(22/647)
- I 3.25%(21/647)
- the 2.94%(19/647)
- a 2.78%(18/647)
- that 2.32%(15/647)
- of 2.01%(13/647)
- with 1.39%(9/647)
- was 1.24%(8/647)
- our 1.24%(8/647)
复制代码- awk '{b[length($0)]++;total_lines++;for(i=1;i<=NF;i++){sub(/^\W+|\W+$/,"",$i);a[$i]++;total_words++}} END{print "Top 10 line characters:";for(i in b)printf "%d字符 %.2f%%(%d/%d)\n",i,100*b[i]/total_lines,b[i],total_lines| "sort -nr -k1 | head -10"}' i
- Top 10 line characters:
- 1016字符 7.69%(1/13)
- 682字符 7.69%(1/13)
- 478字符 7.69%(1/13)
- 445字符 7.69%(1/13)
- 421字符 7.69%(1/13)
- 304字符 7.69%(1/13)
- 135字符 7.69%(1/13)
- 0字符 46.15%(6/13)
复制代码 测试文件i- As a student of adversity, I've been struck over the years by how some people with major challenges seem to draw strength from them, and I've heard the popular wisdom that that has to do with finding meaning. And for a long time, I thought the meaning was out there, some great truth waiting to be found.
- But over time, I've come to feel that the truth is irrelevant. We call it finding meaning, but we might better call it forging meaning.
- My last book was about how families manage to deal with various kinds of challenging or unusual offspring, and one of the mothers I interviewed, who had two children with multiple severe disabilities, said to me, "People always give us these little sayings like, 'God doesn't give you any more than you can handle,' but children like ours are not preordained as a gift. They're a gift because that's what we have chosen."
- We make those choices all our lives. When I was in second grade, Bobby Finkel had a birthday party and invited everyone in our class but me. My mother assumed there had been some sort of error, and she called Mrs. Finkel, who said that Bobby didn't like me and didn't want me at his party. And that day, my mom took me to the zoo and out for a hot fudge sundae. When I was in seventh grade, one of the kids on my school bus nicknamed me "Percy" as a shorthand for my demeanor, and sometimes, he and his cohort would chant that provocation the entire school bus ride, 45 minutes up, 45 minutes back, "Percy! Percy! Percy! Percy!" When I was in eighth grade, our science teacher told us that all male homosexuals develop fecal incontinence because of the trauma to their anal sphincter. And I graduated high school without ever going to the cafeteria, where I would have sat with the girls and been laughed at for doing so, or sat with the boys and been laughed at for being a boy who should be sitting with the girls.
- I survived that childhood through a mix of avoidance and endurance. What I didn't know then, and do know now, is that avoidance and endurance can be the entryway to forging meaning. After you've forged meaning, you need to incorporate that meaning into a new identity. You need to take the traumas and make them part of who you've come to be, and you need to fold the worst events of your life into a narrative of triumph, evincing a better self in response to things that hurt.
- One of the other mothers I interviewed when I was working on my book had been raped as an adolescent, and had a child following that rape, which had thrown away her career plans and damaged all of her emotional relationships. But when I met her, she was 50, and I said to her, "Do you often think about the man who raped you?" And she said, "I used to think about him with anger, but now only with pity." And I thought she meant pity because he was so unevolved as to have done this terrible thing. And I said, "Pity?" And she said, "Yes, because he has a beautiful daughter and two beautiful grandchildren and he doesn't know that, and I do. So as it turns out, I'm the lucky one."
- Some of our struggles are things we're born to: our gender, our sexuality, our race, our disability. And some are things that happen to us: being a political prisoner, being a rape victim, being a Katrina survivor. Identity involves entering a community to draw strength from that community, and to give strength there too. It involves substituting "and" for "but" -- not "I am here but I have cancer," but rather, "I have cancer and I am here."
复制代码 但为什么合在一起输出顺序有点问题,管道的问题吗?有大神能答疑解惑下吗?- awk '{b[length($0)]++;total_lines++;for(i=1;i<=NF;i++){sub(/^\W+|\W+$/,"",$i);a[$i]++;total_words++}} END{print "Top 10 words frequency:";for(i in a)printf "%s %.2f%%(%d/%d)\n",i,100*a[i]/total_words,a[i],total_words| "sort -nr -k2 | head -10";print "Top 10 line characters:";for(i in b)printf "%d字符 %.2f%%(%d/%d)\n",i,100*b[i]/total_lines,b[i],total_lines| "sort -nr -k1 | head -10"}' i
- Top 10 words frequency:
- Top 10 line characters:
- 1016字符 7.69%(1/13)
- 682字符 7.69%(1/13)
- 478字符 7.69%(1/13)
- 445字符 7.69%(1/13)
- 421字符 7.69%(1/13)
- 304字符 7.69%(1/13)
- 135字符 7.69%(1/13)
- 0字符 46.15%(6/13)
- and 3.55%(23/647)
- to 3.40%(22/647)
- I 3.25%(21/647)
- the 2.94%(19/647)
- a 2.78%(18/647)
- that 2.32%(15/647)
- of 2.01%(13/647)
- with 1.39%(9/647)
- was 1.24%(8/647)
- our 1.24%(8/647)
复制代码 |
|