Chinaunix首页 | 论坛 | 博客
  • 博客访问: 265953
  • 博文数量: 54
  • 博客积分: 35
  • 博客等级: 民兵
  • 技术积分: 729
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-09 10:35
文章分类

全部博文(54)

文章存档

2014年(37)

2013年(17)

分类: LINUX

2013-10-27 17:28:59

原帖:

处理前:
ABDCDCDCAAXCXCDCCABABDCDCDCAABXBABDCDCDCAABBCDCCAXDBBXABDCDCDCAABBCDXCCA
BBCDCCABBBABXCDCDCAABBCDXCCABBBBBABDCDCDCAABBCDCCAXBBBABCDAAAXBCDADCAXXX
XABCDCDCAAXBBCCDCCABABDCDCDCAABXBABDABACCCAXCDCDCAABBCDCCABBBXABDCDCDCAA
AACDCCAADCABDCDCDCAABXCDXCXABCDDBABDCDCDCAABBXBXCAABBBABCDAAAXBCDADCABBB
ADCAAAAAXABCDCCCCCDCABXBBCCDCCABABDCDCDCAABXBABDABDCCCAXCDCDCAAAAABBCDCC
XCCCAABDCAAXXAADCCCCCCAACCAAAAAAAAAXBBDCCXACDACDAAXCBBBBBBBAAABCADDCAAXC
XABCDCDCAAXBBCCDCCABABDCDCDCAABXBABDABACCCAXCDCDCAABBCDCCABBBXABDCDCDCAA

处理后:
aBDCDCDCaaxcxcdcCABABDCDcDcAabxbaBDCDCDCAABbCdCcaxdbbxaBDCDCDcAAbbcdxcca
bBCDCCABbBabxcdcDCAAbbcdxccaBBbbBABDCDCDCAAbBcDcCaxbbbABCDAAaxbcDADCaxxx
xaBCDCDCaaxbbCCDCCABAbdCdCdCAabxbaBdABACCCaxcdcdCAaBBcDcCABbbxaBDCDCDcaa
aACDCCAAdCabdCDCDCAabxcdxcxaBCDdBABdCDCDCAAbbxbxcaaBBBAbCDAAaxbcDADCAbbB
aDCAAAAaxaBcdCCCCCDCabxbbCcDCCAbABDcDCDCAabxbaBdABdCCCaxcdcDCaAAAABBCdcC
xcccAABDcAaxxaADCCCCCcaAcCaAAAAaAAaxbbdccxacDACdAaxcbbBbBBBAAaBCADDCAaxc
xaBCDCDCaaxbbCCDCCABABDCDCdCAabxbaBdABACCcaxcdcdCAaBBCDcCABbbxaBDCDCDCaA

处理规则:
数据中的字符X为污染源,纯净的字符为A、B、C、D,我们需要根据X附近(上、下、左、右四个方向)的字符来转化受到污染的字符,A、B、C、D分别代表1、2、3、4长度,例如X左边的字符是A,就表示左边有一个字符被污染了,需要将它转化为小写,如果左边的字符是B,就表示有两个字符被污染,需要把它们转化为小写,但有一种特殊情况,就是遇到字符X时就不需要再继续转化了,其他几个方向同理。如果看不懂我说的可以看看原帖。

点击(此处)折叠或打开

  1. #楼主给的数据
  2. [root@localhost ~]# cat i
  3. ABDCDCDCAAXCXCDCCABABDCDCDCAABXBABDCDCDCAABBCDCCAXDBBXABDCDCDCAABBCDXCCA
  4. BBCDCCABBBABXCDCDCAABBCDXCCABBBBBABDCDCDCAABBCDCCAXBBBABCDAAAXBCDADCAXXX
  5. XABCDCDCAAXBBCCDCCABABDCDCDCAABXBABDABACCCAXCDCDCAABBCDCCABBBXABDCDCDCAA
  6. AACDCCAADCABDCDCDCAABXCDXCXABCDDBABDCDCDCAABBXBXCAABBBABCDAAAXBCDADCABBB
  7. ADCAAAAAXABCDCCCCCDCABXBBCCDCCABABDCDCDCAABXBABDABDCCCAXCDCDCAAAAABBCDCC
  8. XCCCAABDCAAXXAADCCCCCCAACCAAAAAAAAAXBBDCCXACDACDAAXCBBBBBBBAAABCADDCAAXC
  9. XABCDCDCAAXBBCCDCCABABDCDCDCAABXBABDABACCCAXCDCDCAABBCDCCABBBXABDCDCDCAA

  10. #awk脚本1(用于横向标示杂质)
  11. [root@localhost ~]# cat a1
  12. #!/bin/awk -f
  13. BEGIN{
  14.         FS=OFS="";
  15.         IGNORECASE=1;
  16.         a["a"]=a["A"]=1;
  17.         a["b"]=a["B"]=2;
  18.         a["c"]=a["C"]=3;
  19.         a["d"]=a["D"]=4;
  20. }
  21. {
  22.         for(i=1;i<=NF;i++){
  23.                 if($i=="X"){
  24.                         for(j=i-1;j>=i-a[$(i-1)]&&j>=1;j--){
  25.                                 if($j=="X")break;
  26.                                 $j=tolower($j)
  27.                         }
  28.                         for(j=i+1;j<=i+a[$(i+1)]&&j<=NF;j++){
  29.                                 if($j=="X")break;
  30.                                 $j=tolower($j)
  31.                         }
  32.                         $i=tolower($i)
  33.                 }
  34.         }
  35. }
  36. 1

  37. #awk脚本2(用于行列转换)
  38. [root@localhost ~]# cat a2
  39. #!/bin/awk -f
  40. BEGIN{
  41.         FS=""
  42. }
  43. {
  44.         for(i=1;i<=NF;i++)a[i]=a[i]$i
  45. }
  46. END{
  47.         for(i=1;i<=NF;i++)print a[i]
  48. }

  49. #运行方法和结果(运行前先赋予脚本a1和a2可执行权限)
  50. [root@localhost ~]# ./a1 i | ./a2 | ./a1 | ./a2
  51. aBDCDCDCaaxcxcdcCABABDCDcDcAabxbaBDCDCDCAABbCdCcaxdbbxaBDCDCDcAAbbcdxcca
  52. bBCDCCABbBabxcdcDCAAbbcdxccaBBbbBABDCDCDCAAbBcDcCaxbbbABCDAAaxbcDADCaxxx
  53. xaBCDCDCaaxbbCCDCCABAbdCdCdCAabxbaBdABACCCaxcdcdCAaBBcDcCABbbxaBDCDCDcaa
  54. aACDCCAAdCabdCDCDCAabxcdxcxaBCDdBABdCDCDCAAbbxbxcaaBBBAbCDAAaxbcDADCAbbB
  55. aDCAAAAaxaBcdCCCCCDCabxbbCcDCCAbABDcDCDCAabxbaBdABdCCCaxcdcDCaAAAABBCdcC
  56. xcccAABDcAaxxaADCCCCCcaAcCaAAAAaAAaxbbdccxacDACdAaxcbbBbBBBAAaBCADDCAaxc
  57. xaBCDCDCaaxbbCCDCCABABDCDCdCAabxbaBdABACCcaxcdcdCAaBBCDcCABbbxaBDCDCDCaA

点击(此处)折叠或打开

  1. [root@localhost ~]# cat a
  2. #!/bin/awk
  3. BEGIN{
  4.         FS="";
  5.         IGNORECASE=1;
  6.         a["a"]=a["A"]=1;
  7.         a["b"]=a["B"]=2;
  8.         a["c"]=a["C"]=3;
  9.         a["d"]=a["D"]=4
  10. }
  11. {
  12.         for(i=1;i<=NF;i++)b[NR,i]=$i
  13. }
  14. END{
  15.         for(i=1;i<=NR;i++){
  16.                 for(j=1;j<=NF;j++){
  17.                         if(b[i,j]=="X"){
  18.                                 for(k=j-1;k>=j-a[b[i,j-1]]&&k>=1;k--){
  19.                                         if(b[i,k]=="X")break;
  20.                                         b[i,k]=tolower(b[i,k])
  21.                                 }
  22.                                 for(k=j+1;k<=j+a[b[i,j+1]]&&k<=NF;k++){
  23.                                         if(b[i,k]=="X")break;
  24.                                         b[i,k]=tolower(b[i,k])
  25.                                 }
  26.                                 b[i,j]=tolower(b[i,j])
  27.                         }
  28.                 }
  29.         }
  30.         for(i=1;i<=NF;i++){
  31.                 for(j=1;j<=NR;j++){
  32.                         if(b[j,i]=="X"){
  33.                                 for(k=j-1;k>=j-a[b[j-1,i]]&&k>=1;k--){
  34.                                         if(b[k,i]=="X")break;
  35.                                         b[k,i]=tolower(b[k,i])
  36.                                 }
  37.                                 for(k=j+1;k<=j+a[b[j+1,i]]&&k<=NR;k++){
  38.                                         if(b[k,i]=="X")break;
  39.                                         b[k,i]=tolower(b[k,i])
  40.                                 }
  41.                                 b[j,i]=tolower(b[j,i])
  42.                         }
  43.                 }
  44.         }
  45.         for(i=1;i<=NR;i++){
  46.                 for(j=1;j<NF;j++)printf b[i,j];
  47.                 print b[i,NF]
  48.         }
  49. }

其他人的代码请看原帖。
阅读(1192) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~