免费注册 查看新帖 |

Chinaunix

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

求大神帮忙 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-05-04 23:00 |只看该作者 |倒序浏览
2.        使用for循环将下面这段话中所有字母长度超过5的单词打印出来。
“When you're attracted to someone it just means that your subconscious is attracted to their subconscious, subconsciously.
So what we think of as fate, is just two neuroses knowing they're a perfect match.”

论坛徽章:
1
操作系统版块每日发帖之星
日期:2016-05-26 06:20:00
2 [报告]
发表于 2016-05-23 09:19 |只看该作者
#!/bin/sh
FILE="When you're attracted to someone it just means that your subconscious is attracted to their subconscious, subconsciously.So what we think of as fate, is just two neuroses knowing they're a perfect match"
NUM=`echo $FILE | wc -w`
for ((i=1;i<=$NUM;i++))
do
WORD=`echo $FILE | awk '{print $'$i'}'`
CNUM=`echo $WORD | wc -c`
if [ $CNUM -gt 6 ];
then
echo $WORD
fi
done

论坛徽章:
4
程序设计版块每日发帖之星
日期:2016-08-11 06:20:00数据库技术版块每日发帖之星
日期:2016-08-13 06:20:00程序设计版块每日发帖之星
日期:2016-08-14 06:20:00数据库技术版块每日发帖之星
日期:2016-08-14 06:20:00
3 [报告]
发表于 2016-08-11 09:06 |只看该作者
本帖最后由 杰瑞26 于 2016-08-11 09:10 编辑

  1. #!/bin/bash
  2. # filename: test.sh

  3. sentence="When you're attracted to someone it just means that your subconscious is attracted to their subconscious, subconsciously.
  4. So what we think of as fate, is just two neuroses knowing they're a perfect match."

  5. for word in ${sentence}
  6. do
  7.     new=`echo $word | tr -cd '[a-zA-Z]'`  # 去除句子中的 ,或者'
  8.     len=${#new}                           # 求长度
  9.     if [ "$len" -ge 5 ]                   # 再判断
  10.     then
  11.         echo $new
  12.     fi
  13. done
复制代码
结果输出:
  1. root@localhost:~/training# ./test.sh
  2. youre
  3. attracted
  4. someone
  5. means
  6. subconscious
  7. attracted
  8. their
  9. subconscious
  10. subconsciously
  11. think
  12. neuroses
  13. knowing
  14. theyre
  15. perfect
  16. match
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP