免费注册 查看新帖 |

Chinaunix

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

同一段shell处理Win 文本和 *nux文本的不同结果,求分析!!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-04-22 18:22 |只看该作者 |倒序浏览
这是处理win文本的结果
  1. ShllyXZ shell # cat t1.txt
  2. 2011-4-1:5
  3. 2011-4-2:7
  4. 2011-4-3:3456
  5. ShllyXZ shell # cat t2.txt
  6. 2011-4-1:3
  7. 2011-4-2:4
  8. 2011-4-3:5
  9. ShllyXZ shell # cat s1
  10. #!/bin/bash
  11. i=1
  12. while [ "$i" -le 4 ]
  13. do
  14.   va=`awk 'BEGIN{FS=":"}/\<2011-4-'$i'\>/{print $2}' t1.txt`
  15.   vb=`awk 'BEGIN{FS=":"}/\<2011-4-'$i'\>/{print $2}' t2.txt`
  16.   echo "this is va:$va and vb:$vb"
  17.   echo "this is a+b=$va+$vb"
  18.   echo "this is va:$va"

  19.   i=$(($i+1))
  20. done
  21. ShllyXZ shell # ./s1
  22. and vb:3a:5                        # 其实我知道是换行符的结果,但是不明白为什么会产生这种输出?
  23. +3is is a+b=5
  24. this is va:5
  25. and vb:4a:7
  26. +4is is a+b=7
  27. this is va:7
  28. and vb:5a:3456
  29. +5is is a+b=3456
  30. this is va:3456
  31. this is va: and vb:
  32. this is a+b=+
  33. this is va:
复制代码
下面是处理*nix文本的结果,是正常的:
  1. ShllyXZ shell # cat t1
  2. 2011-4-1:5
  3. 2011-4-2:7
  4. 2011-4-3:22789
  5. 2011-4-4:38275
  6. 2011-4-5:38200
  7. 2011-4-6:40064
  8. 2011-4-7:38565
  9. 2011-4-8:38561
  10. 2011-4-9:36938
  11. 2011-4-10:6480ShllyXZ shell # cat t2
  12. 2011-4-1:5
  13. 2011-4-2:18
  14. 2011-4-3:23079
  15. 2011-4-4:0
  16. 2011-4-5:38126
  17. 2011-4-6:36643
  18. 2011-4-7:38522
  19. 2011-4-8:38341
  20. 2011-4-9:37817
  21. 2011-4-10:6347
  22. ShllyXZ shell # cat s1
  23. #!/bin/bash
  24. i=1
  25. while [ "$i" -le 4 ]
  26. do
  27.   va=`awk 'BEGIN{FS=":"}/\<2011-4-'$i'\>/{print $2}' t1`
  28.   vb=`awk 'BEGIN{FS=":"}/\<2011-4-'$i'\>/{print $2}' t2`
  29.   echo "this is va:$va and vb:$vb"
  30.   echo "this is a+b=$va+$vb"
  31.   echo "this is va:$va"

  32.   i=$(($i+1))
  33. done
  34. ShllyXZ shell # ./s1
  35. this is va:5 and vb:5
  36. this is a+b=5+5
  37. this is va:5
  38. this is va:7 and vb:18
  39. this is a+b=7+18
  40. this is va:7
  41. this is va:22789 and vb:23079
  42. this is a+b=22789+23079
  43. this is va:22789
  44. this is va:38275 and vb:0
  45. this is a+b=38275+0
  46. this is va:38275
复制代码
请教了

论坛徽章:
3
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:51:162015年亚洲杯之阿曼
日期:2015-04-07 20:00:59
2 [报告]
发表于 2011-04-22 18:58 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP