腾讯一shell试题.

腾讯一shell试题.

            假设qq.tel文件内容:

              12334:13510014336

              12345:12334555666

              12334:12343453453

              12099:13598989899

              12334:12345454545

              12099:12343454544

            分类如下:

              [12334]

                  13510014336

                  12343453453

                  ...........

              [12099]

                  13598989899

                  12343454544

                  ............

          实现如下:

                                sort  qq.tel| awk  -F':'   '{if(tmp!=$1)   {tmp=$1;print "["tmp"]";}  print $2;}'  #tmp可以换成其他字符           判断tmp是否不等于   不等于就把$1赋值给tmp      打印tmp的值"tmp“   打印$2 

 

 

sort 11.txt |awk '{if(tmp!=$1){tmp=$1;print "["tmp"]"}print $2}'

 

 

找出两个文件中一样的qq号

1 #!/bin/bash
  2 for string1 in `cat a.txt`;do
  3     for string2 in `cat b.txt`;do
  4         if [ "$string1" == "$string2" ];then
  5             echo $string1
  6         fi
  7     done
  8 done     

 

posted on 2015-01-17 18:35  寒星12345678999  阅读(262)  评论(0编辑  收藏  举报