Chinaunix首页 | 论坛 | 博客
  • 博客访问: 554469
  • 博文数量: 116
  • 博客积分: 2063
  • 博客等级: 大尉
  • 技术积分: 1174
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-26 16:44
个人简介

none

文章分类

全部博文(116)

文章存档

2023年(2)

2020年(3)

2019年(4)

2018年(7)

2017年(6)

2016年(17)

2015年(13)

2014年(19)

2013年(6)

2012年(13)

2011年(5)

2010年(11)

2008年(10)

分类: LINUX

2012-10-31 08:20:14

从汇率网站 
copy的原始格式数字保存在usdcny_From2007.data,共1521条记录

[root@] ~]# head -4 usdcny_From2007.data 
 Date    Open    High    Low     Close
Tue, Oct 30 2012 6.2447  6.2450  6.2446  6.2446
Mon, Oct 29 2012 6.2530  6.2662  6.2398  6.2446
Fri, Oct 26 2012 6.2437  6.2627  6.2437  6.2627
[root@] ~]# 
[root@] ~]# cat usdcny_From2007.data | wc -l
1522 
[root@] ~]# cat format.sh   

点击(此处)折叠或打开

  1. #!/bin/sh
  2. # 1 2 3 4 5_O 6_H 7_L 8_C
  3. # FROM ----- Mon, Jan 01 2007 7.8185 7.8185 7.8115 7.8185
  4. #
  5. # T O ----- 7.8115 2007_Jan_01____7.8115
  6. #

  7. awk -F' ' \
  8. '{
  9. if (NF == 8)
  10.     {
  11.         VAL=length($7);
  12.         if(VAL == 1)
  13.             print $7".0000 "$4"_"$2"_"$3"____"$7".0000";
  14.         else if(VAL == 3)
  15.             print $7"000 "$4"_"$2"_"$3"____"$7"000";
  16.         else if(VAL == 4)
  17.             print $7"00 "$4"_"$2"_"$3"____"$7"00";
  18.         else if(VAL == 5)
  19.             print $7"0 "$4"_"$2"_"$3"____"$7"0";
  20.         else
  21.             print $7" "$4"_"$2"_"$3"____"$7;
  22.     }
  23. }' usdcny_From2007.data

[root@] ~]#
[root@] ~]# sh format.sh > usdcny_From2007_Lowest.data 
[root@] ~]# 
[root@] ~]# head -2 usdcny_From2007_Lowest.data
6.2446 2012_Oct_30____6.2446
6.2398 2012_Oct_29____6.2398
[root@] ~]# 
[root@] ~]# tail -3 usdcny_From2007_Lowest.data     
7.8135 2007_Jan_03____7.8135
7.8160 2007_Jan_02____7.8160
7.8115 2007_Jan_01____7.8115
[root@] ~]# 
[root@] ~]# cat usdcny_From2007_Lowest.data | wc -l
1521
[root@] ~]# cat sort_by_lowest.sh

点击(此处)折叠或打开

  1. #!/bin/sh

  2. CMP_FLAG=1
  3. SHOW_FLAG=0

  4. VAL=7.8115

  5. if [ $# -eq 2 ];then
  6.     echo "input file is "$1" and the default compile val is "$2""
  7.     VAL=$2
  8.     echo VAL=$VAL
  9. else
  10.     echo "USAGE : $0 FILE_NAME CMP_VAL"
  11.     exit -1
  12. fi

  13. #
  14. # Other method of read files with reverse sequence
  15. #
  16. # sed -n '1!G;h;$p' urfile VS tac
  17. #

  18. for i in `tac $1`;
  19. do
  20.     if [ $CMP_FLAG -eq 1 ];then
  21.         CMP_FLAG=0;

  22.         #
  23.         # How to compare float data in BASH
  24.         #
  25.         # Method 1: echo 123.45 123.44 | awk '{if($1>$2){printf"%f greater then %f\n",$1,$2}else{printf"%f less then %f\n",$1,$2}}'
  26.         # Method 2: or use command let: A=1;B=4;let "C=A+B";echo $C # but only works with integer data
  27.         # Method 3: echo " 123.45 > 123.44" | bc
  28.         #
  29.         if [ `echo "$i < $VAL" | bc` -eq 1 ];then # For Lowest record
  30.             VAL=$i
  31.             SHOW_FLAG=1;
  32.         fi
  33.     else
  34.         CMP_FLAG=1;
  35.         if [ $SHOW_FLAG -eq 1 ];then
  36.             SHOW_FLAG=0;

  37.             #7.7260 2007_Mar_22____7.7260

  38.             len=`expr length $VAL`;
  39.             if [ $len -eq 1 ];then
  40.                 echo $VAL".0000 "$i".0000";
  41.             elif [ $len -eq 3 ];then
  42.                 echo $VAL"000 "$i"000";
  43.             elif [ $len -eq 4 ];then
  44.                 echo $VAL"00 "$i"00";
  45.             elif [ $len -eq 5 ];then
  46.                 echo $VAL"0 "$i"0";
  47.             else
  48.                 echo $VAL" "$i;
  49.             fi
  50.         fi
  51.     fi
  52. done

[root@] ~]# 
[root@] ~]# sh sort_by_lowest.sh usdcny_From2007_Lowest.data 
USAGE : sort_by_lowest.sh FILE_NAME CMP_VAL
[root@] ~]# 
[root@] ~]# time sh sort_by_lowest.sh usdcny_From2007_Lowest.data 7.8115 > usdcny_From2007_Lowest_new.data
real    0m10.247s
user    0m0.401s
sys     0m9.842s
[root@] ~]# 
[root@] ~]# cat usdcny_From2007_Lowest_new.data

点击(此处)折叠或打开

  1. input file is usdcny_From2007_Lowest.data and the default compile val is 7.8115
  2. VAL=7.8115
  3. 7.8030 2007_Jan_04____7.8030
  4. 7.7965 2007_Jan_11____7.7965
  5. 7.7948 2007_Jan_12____7.7948
  6. 7.7925 2007_Jan_15____7.7925
  7. 7.7880 2007_Jan_16____7.7880
  8. 7.7750 2007_Jan_17____7.7750
  9. 7.7705 2007_Jan_18____7.7705
  10. 7.7680 2007_Jan_25____7.7680
  11. 7.7552 2007_Feb_01____7.7552
  12. 7.7550 2007_Feb_02____7.7550
  13. 7.7470 2007_Feb_07____7.7470
  14. 7.7405 2007_Feb_09____7.7405
  15. 7.7395 2007_Feb_16____7.7395
  16. 7.7345 2007_Feb_27____7.7345
  17. 7.7100 2007_Mar_01____7.7100
  18. 7.7039 2007_Apr_30____7.7039
  19. 7.6939 2007_May_08____7.6939
  20. 7.6935 2007_May_09____7.6935
  21. 7.6766 2007_May_11____7.6766
  22. 7.6715 2007_May_14____7.6715
  23. 7.6705 2007_May_17____7.6705
  24. 7.6680 2007_May_18____7.6680
  25. 7.6625 2007_May_21____7.6625
  26. 7.6525 2007_May_22____7.6525
  27. 7.6480 2007_May_23____7.6480
  28. 7.6450 2007_May_28____7.6450
  29. 7.6385 2007_Jun_05____7.6385
  30. 7.6342 2007_Jun_06____7.6342
  31. 7.6260 2007_Jun_13____7.6260
  32. 7.6205 2007_Jun_14____7.6205
  33. 7.6200 2007_Jun_18____7.6200
  34. 7.6175 2007_Jun_19____7.6175
  35. 7.6160 2007_Jun_20____7.6160
  36. 7.6159 2007_Jun_26____7.6159
  37. 7.6155 2007_Jun_27____7.6155
  38. 7.6150 2007_Jun_28____7.6150
  39. 7.6132 2007_Jun_29____7.6132
  40. 7.6047 2007_Jul_02____7.6047
  41. 7.5930 2007_Jul_03____7.5930
  42. 7.5800 2007_Jul_10____7.5800
  43. 7.5615 2007_Jul_11____7.5615
  44. 7.5314 2007_Jul_17____7.5314
  45. 7.5195 2007_Sep_10____7.5195
  46. 7.5085 2007_Sep_13____7.5085
  47. 7.5002 2007_Sep_21____7.5002
  48. 7.5000 2007_Oct_08____7.5000
  49. 7.4910 2007_Oct_24____7.4910
  50. 7.4805 2007_Oct_25____7.4805
  51. 7.4710 2007_Oct_26____7.4710
  52. 7.4695 2007_Oct_30____7.4695
  53. 7.4605 2007_Oct_31____7.4605
  54. 7.4505 2007_Nov_01____7.4505
  55. 7.4405 2007_Nov_07____7.4405
  56. 7.4200 2007_Nov_08____7.4200
  57. 7.4095 2007_Nov_09____7.4095
  58. 7.4010 2007_Nov_22____7.4010
  59. 7.3970 2007_Nov_23____7.3970
  60. 7.3917 2007_Nov_26____7.3917
  61. 7.3835 2007_Nov_27____7.3835
  62. 7.3795 2007_Nov_29____7.3795
  63. 7.3760 2007_Dec_11____7.3760
  64. 7.3674 2007_Dec_12____7.3674
  65. 7.3615 2007_Dec_13____7.3615
  66. 7.3584 2007_Dec_14____7.3584
  67. 7.3470 2007_Dec_24____7.3470
  68. 7.3275 2007_Dec_25____7.3275
  69. 7.3270 2007_Dec_26____7.3270
  70. 7.3095 2007_Dec_27____7.3095
  71. 7.3030 2007_Dec_28____7.3030
  72. 7.2900 2008_Jan_02____7.2900
  73. 7.2705 2008_Jan_03____7.2705
  74. 7.2693 2008_Jan_04____7.2693
  75. 7.2610 2008_Jan_07____7.2610
  76. 7.2605 2008_Jan_09____7.2605
  77. 7.2100 2008_Jan_10____7.2100
  78. 7.2097 2008_Jan_25____7.2097
  79. 7.1940 2008_Jan_28____7.1940
  80. 7.1915 2008_Jan_29____7.1915
  81. 7.1895 2008_Jan_30____7.1895
  82. 7.1800 2008_Jan_31____7.1800
  83. 7.1500 2008_Feb_05____7.1500
  84. 7.1480 2008_Feb_19____7.1480
  85. 7.1425 2008_Feb_20____7.1425
  86. 7.1395 2008_Feb_21____7.1395
  87. 7.1100 2008_Feb_28____7.1100
  88. 7.1025 2008_Feb_29____7.1025
  89. 7.1000 2008_Mar_03____7.1000
  90. 7.0000 2008_Mar_07____7.0000
  91. 6.9995 2008_Apr_09____6.9995
  92. 6.9895 2008_Apr_10____6.9895
  93. 6.9825 2008_Apr_17____6.9825
  94. 6.9800 2008_Apr_23____6.9800
  95. 6.9700 2008_May_19____6.9700
  96. 6.9545 2008_May_21____6.9545
  97. 6.9410 2008_May_22____6.9410
  98. 6.9400 2008_May_23____6.9400
  99. 6.9355 2008_May_26____6.9355
  100. 6.9345 2008_May_29____6.9345
  101. 6.9320 2008_Jun_02____6.9320
  102. 6.9245 2008_Jun_03____6.9245
  103. 6.9205 2008_Jun_06____6.9205
  104. 6.9190 2008_Jun_10____6.9190
  105. 6.9170 2008_Jun_11____6.9170
  106. 6.9000 2008_Jun_12____6.9000
  107. 6.8999 2008_Jun_16____6.8999
  108. 6.8895 2008_Jun_17____6.8895
  109. 6.8800 2008_Jun_18____6.8800
  110. 6.8735 2008_Jun_19____6.8735
  111. 6.8695 2008_Jun_23____6.8695
  112. 6.8683 2008_Jun_24____6.8683
  113. 6.8639 2008_Jun_25____6.8639
  114. 6.8607 2008_Jun_26____6.8607
  115. 6.8595 2008_Jun_27____6.8595
  116. 6.8535 2008_Jun_30____6.8535
  117. 6.8506 2008_Jul_01____6.8506
  118. 6.8470 2008_Jul_03____6.8470
  119. 6.8420 2008_Jul_10____6.8420
  120. 6.8331 2008_Jul_11____6.8331
  121. 6.8261 2008_Jul_14____6.8261
  122. 6.8200 2008_Jul_15____6.8200
  123. 6.8103 2008_Jul_16____6.8103
  124. 6.8100 2008_Jul_17____6.8100
  125. 6.8085 2008_Sep_24____6.8085
  126. 6.6310 2010_Apr_02____6.6310
  127. 6.6235 2010_Sep_29____6.6235
  128. 6.6115 2010_Oct_04____6.6115
  129. 6.6015 2010_Dec_30____6.6015
  130. 6.5897 2010_Dec_31____6.5897
  131. 6.5885 2011_Jan_05____6.5885
  132. 6.5880 2011_Jan_17____6.5880
  133. 6.5834 2011_Jan_18____6.5834
  134. 6.5815 2011_Jan_19____6.5815
  135. 6.5805 2011_Jan_24____6.5805
  136. 6.5765 2011_Jan_25____6.5765
  137. 6.5585 2011_Feb_02____6.5585
  138. 6.5535 2011_Feb_08____6.5535
  139. 6.5515 2011_Mar_22____6.5515
  140. 6.5455 2011_Mar_31____6.5455
  141. 6.5375 2011_Apr_04____6.5375
  142. 6.5365 2011_Apr_07____6.5365
  143. 6.5363 2011_Apr_08____6.5363
  144. 6.5358 2011_Apr_11____6.5358
  145. 6.5275 2011_Apr_12____6.5275
  146. 6.5215 2011_Apr_15____6.5215
  147. 6.5100 2011_Apr_20____6.5100
  148. 6.4935 2011_Apr_21____6.4935
  149. 6.4805 2011_Apr_29____6.4805
  150. 6.4630 2011_May_02____6.4630
  151. 6.4550 2011_Jun_14____6.4550
  152. 6.4495 2011_Jul_21____6.4495
  153. 6.4450 2011_Jul_22____6.4450
  154. 6.4395 2011_Jul_26____6.4395
  155. 6.4375 2011_Jul_29____6.4375
  156. 6.4336 2011_Aug_01____6.4336
  157. 6.4332 2011_Aug_02____6.4332
  158. 6.4265 2011_Aug_08____6.4265
  159. 6.4154 2011_Aug_10____6.4154
  160. 6.3913 2011_Aug_11____6.3913
  161. 6.3907 2011_Aug_12____6.3907
  162. 6.3893 2011_Aug_15____6.3893
  163. 6.3838 2011_Aug_16____6.3838
  164. 6.3830 2011_Aug_17____6.3830
  165. 6.3801 2011_Aug_29____6.3801
  166. 6.3787 2011_Aug_30____6.3787
  167. 6.3772 2011_Aug_31____6.3772
  168. 6.3770 2011_Sep_01____6.3770
  169. 6.3750 2011_Oct_03____6.3750
  170. 6.3453 2011_Oct_10____6.3453
  171. 6.3375 2011_Oct_11____6.3375
  172. 6.3365 2011_Nov_09____6.3365
  173. 6.3350 2011_Dec_06____6.3350
  174. 6.3020 2011_Dec_19____6.3020
  175. 6.2939 2011_Dec_30____6.2939
  176. 6.2540 2012_Jan_02____6.2540
  177. 6.2535 2012_Oct_17____6.2535
  178. 6.2476 2012_Oct_18____6.2476
  179. 6.2407 2012_Oct_19____6.2407
  180. 6.2398 2012_Oct_29____6.2398

[root@] ~]# 
[root@] ~]# cat usdcny_From2007_Lowest_new.data | wc -l
180
[root@] ~]# cat usdcny_From2007_Lowest_new.data | grep "2007" | wc -l
70
[root@] ~]# cat usdcny_From2007_Lowest_new.data | grep "2008" | wc -l 
54
[root@] ~]# cat usdcny_From2007_Lowest_new.data | grep "2009" | wc -l 
0
[root@] ~]# cat usdcny_From2007_Lowest_new.data | grep "2010" | wc -l  
5
[root@] ~]# cat usdcny_From2007_Lowest_new.data | grep "2011" | wc -l 
45
[root@] ~]# cat usdcny_From2007_Lowest_new.data | grep "2012" | wc -l 
5
可见2007/2008/2011升值频率很高!
阅读(880) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~