免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4897 | 回复: 6
打印 上一主题 下一主题

[文本处理] 如何统计文本中某个单词出现的次数 [复制链接]

论坛徽章:
307
程序设计版块每周发帖之星
日期:2016-04-08 00:41:33操作系统版块每日发帖之星
日期:2015-09-02 06:20:00每日论坛发贴之星
日期:2015-09-02 06:20:00程序设计版块每日发帖之星
日期:2015-09-04 06:20:00每日论坛发贴之星
日期:2015-09-04 06:20:00每周论坛发贴之星
日期:2015-09-06 22:22:00程序设计版块每日发帖之星
日期:2015-09-09 06:20:00程序设计版块每日发帖之星
日期:2015-09-19 06:20:00程序设计版块每日发帖之星
日期:2015-09-20 06:20:00每日论坛发贴之星
日期:2015-09-20 06:20:00程序设计版块每日发帖之星
日期:2015-09-22 06:20:00程序设计版块每日发帖之星
日期:2015-09-24 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-03-19 17:43 |只看该作者 |倒序浏览
本帖最后由 sunzhiguolu 于 2016-03-19 17:53 编辑
THE RIME OF THE ANCYENT MARINERE, IN SEVEN PARTS.
ARGUMENT.
How a Ship having passed the Line was driven by Storms to the cold Country towards the South Pole; and how from thence she made her course to the tropical Latitude of the Great Pacific Ocean; and of the strange things that befell; and in what manner the Ancyent Marinere came back to his own Country.
I.
     It is an ancyent Marinere,
       And he stoppeth one of three:
     "By thy long grey beard and thy glittering eye
       "Now wherefore stoppest me?
     "The Bridegroom's doors are open'd wide
       "And I am next of kin;
     "The Guests are met, the Feast is set,--
       "May'st hear the merry din.--
     But still he holds the wedding-guest--
       There was a Ship, quoth he--
     "Nay, if thou'st got a laughsome tale,
       "Marinere! come with me."
     He holds him with his skinny hand,
       Quoth he, there was a Ship--
     "Now get thee hence, thou grey-beard Loon!
       "Or my Staff shall make thee skip."
     He holds him with his glittering eye--
       The wedding guest stood still
     And listens like a three year's child;
       The Marinere hath his will.
     The wedding-guest sate on a stone,
       He cannot chuse but hear:
     And thus spake on that ancyent man,
       The bright-eyed Marinere.
     The Ship was cheer'd, the Harbour clear'd--

1.> 比如希望统计单词 the 出现的次数. (统计时忽略单词的大小写)

论坛徽章:
50
15-16赛季CBA联赛之广夏
日期:2018-11-05 09:42:462015年亚冠纪念徽章
日期:2015-07-23 11:58:122015亚冠之广州富力
日期:2015-07-07 08:26:172015亚冠之塔什干棉农
日期:2015-06-29 09:08:072015年亚洲杯之伊朗
日期:2015-03-08 20:51:012015年迎新春徽章
日期:2015-03-04 09:58:11未羊
日期:2014-10-16 22:41:47处女座
日期:2014-10-16 15:33:33酉鸡
日期:2014-03-13 12:54:10巳蛇
日期:2014-03-10 14:39:052015亚冠之德黑兰石油
日期:2015-07-29 12:46:372015亚冠之德黑兰石油
日期:2015-08-07 12:54:11
2 [报告]
发表于 2016-03-19 17:53 |只看该作者
  1. grep -io 'the' file|wc -l
复制代码

论坛徽章:
307
程序设计版块每周发帖之星
日期:2016-04-08 00:41:33操作系统版块每日发帖之星
日期:2015-09-02 06:20:00每日论坛发贴之星
日期:2015-09-02 06:20:00程序设计版块每日发帖之星
日期:2015-09-04 06:20:00每日论坛发贴之星
日期:2015-09-04 06:20:00每周论坛发贴之星
日期:2015-09-06 22:22:00程序设计版块每日发帖之星
日期:2015-09-09 06:20:00程序设计版块每日发帖之星
日期:2015-09-19 06:20:00程序设计版块每日发帖之星
日期:2015-09-20 06:20:00每日论坛发贴之星
日期:2015-09-20 06:20:00程序设计版块每日发帖之星
日期:2015-09-22 06:20:00程序设计版块每日发帖之星
日期:2015-09-24 06:20:00
3 [报告]
发表于 2016-03-19 17:53 |只看该作者
本帖最后由 sunzhiguolu 于 2016-03-19 17:54 编辑

2.> 我如果想再统计一下一行的开头至少有一个空白字符后面跟有单词 the 的行数, 命令该如何写. 谢谢大家...

论坛徽章:
307
程序设计版块每周发帖之星
日期:2016-04-08 00:41:33操作系统版块每日发帖之星
日期:2015-09-02 06:20:00每日论坛发贴之星
日期:2015-09-02 06:20:00程序设计版块每日发帖之星
日期:2015-09-04 06:20:00每日论坛发贴之星
日期:2015-09-04 06:20:00每周论坛发贴之星
日期:2015-09-06 22:22:00程序设计版块每日发帖之星
日期:2015-09-09 06:20:00程序设计版块每日发帖之星
日期:2015-09-19 06:20:00程序设计版块每日发帖之星
日期:2015-09-20 06:20:00每日论坛发贴之星
日期:2015-09-20 06:20:00程序设计版块每日发帖之星
日期:2015-09-22 06:20:00程序设计版块每日发帖之星
日期:2015-09-24 06:20:00
4 [报告]
发表于 2016-03-19 17:55 |只看该作者
本帖最后由 sunzhiguolu 于 2016-03-19 17:58 编辑

回复 2# WilliBhamlll
大神回帖好快啊!
试了下, 没有问题, 多谢大神...
   

论坛徽章:
50
15-16赛季CBA联赛之广夏
日期:2018-11-05 09:42:462015年亚冠纪念徽章
日期:2015-07-23 11:58:122015亚冠之广州富力
日期:2015-07-07 08:26:172015亚冠之塔什干棉农
日期:2015-06-29 09:08:072015年亚洲杯之伊朗
日期:2015-03-08 20:51:012015年迎新春徽章
日期:2015-03-04 09:58:11未羊
日期:2014-10-16 22:41:47处女座
日期:2014-10-16 15:33:33酉鸡
日期:2014-03-13 12:54:10巳蛇
日期:2014-03-10 14:39:052015亚冠之德黑兰石油
日期:2015-07-29 12:46:372015亚冠之德黑兰石油
日期:2015-08-07 12:54:11
5 [报告]
发表于 2016-03-19 17:59 |只看该作者
回复 4# sunzhiguolu


    正好看到了

第二问:
  1. grep -io '\s\+the' file|wc -l
复制代码

论坛徽章:
307
程序设计版块每周发帖之星
日期:2016-04-08 00:41:33操作系统版块每日发帖之星
日期:2015-09-02 06:20:00每日论坛发贴之星
日期:2015-09-02 06:20:00程序设计版块每日发帖之星
日期:2015-09-04 06:20:00每日论坛发贴之星
日期:2015-09-04 06:20:00每周论坛发贴之星
日期:2015-09-06 22:22:00程序设计版块每日发帖之星
日期:2015-09-09 06:20:00程序设计版块每日发帖之星
日期:2015-09-19 06:20:00程序设计版块每日发帖之星
日期:2015-09-20 06:20:00每日论坛发贴之星
日期:2015-09-20 06:20:00程序设计版块每日发帖之星
日期:2015-09-22 06:20:00程序设计版块每日发帖之星
日期:2015-09-24 06:20:00
6 [报告]
发表于 2016-03-19 18:06 |只看该作者
本帖最后由 sunzhiguolu 于 2016-03-19 18:08 编辑

回复 5# WilliBhamlll
统计一下一行的开头至少有一个空白字符后面跟有单词 the 的行数
THE RIME OF THE ANCYENT MARINERE, IN SEVEN PARTS.
红色加粗字体的 the 我不想将其计算在内, 谢谢...

   

论坛徽章:
307
程序设计版块每周发帖之星
日期:2016-04-08 00:41:33操作系统版块每日发帖之星
日期:2015-09-02 06:20:00每日论坛发贴之星
日期:2015-09-02 06:20:00程序设计版块每日发帖之星
日期:2015-09-04 06:20:00每日论坛发贴之星
日期:2015-09-04 06:20:00每周论坛发贴之星
日期:2015-09-06 22:22:00程序设计版块每日发帖之星
日期:2015-09-09 06:20:00程序设计版块每日发帖之星
日期:2015-09-19 06:20:00程序设计版块每日发帖之星
日期:2015-09-20 06:20:00每日论坛发贴之星
日期:2015-09-20 06:20:00程序设计版块每日发帖之星
日期:2015-09-22 06:20:00程序设计版块每日发帖之星
日期:2015-09-24 06:20:00
7 [报告]
发表于 2016-03-19 18:18 |只看该作者
第二问已经搞定, 多谢大神...
  1. grep -Eic "^[ \t]+the\>" rime.txt
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP