+ -
当前位置:首页 → 问答吧 → AWK 设置RS变量后影响其他变量吗?

AWK 设置RS变量后影响其他变量吗?

时间:2011-07-22

来源:互联网

如下:
设置RS=c1后,a变量输出不同,为什么?
  1. [root@root-linux ]$ awk '/AAA/,/BBB/{a=$0;RS=c1;print a}' t3
  2. AAA
  3. ndc-mon2
  4. -------------------------------------------
  5. c1              Disk            ENABLED      Disk
  6. c3              GENESIS         ENABLED      USP4
  7. c4              GENESIS         ENABLED      USP4
  8. BBB
  9. ndc-mon3
  10. -------------------------------------------
  11. c2              AMS_WMS         ENABLED      AMS2
  12. c3              AMS_WMS         ENABLED      AMS2
  13. c3              TagmaStore-USP  ENABLED      USP4
  14. c2              TagmaStore-USP  ENABLED      USP4
  15. c1              Disk            ENABLED      disk
  16. [root@root-linux ]$ awk '/AAA/,/BBB/{a=$0;print a}' t3
  17. AAA
  18. ndc-mon2
  19. -------------------------------------------
  20. c1              Disk            ENABLED      Disk
  21. c3              GENESIS         ENABLED      USP4
  22. c4              GENESIS         ENABLED      USP4
  23. BBB
  24. [root@root-linux ]$ cat t3
  25. ndc-mon1
  26. -------------------------------------------
  27. c1              Disk            ENABLED      Disk
  28. c3              GENESIS         ENABLED      USP4
  29. c4              GENESIS         ENABLED      USP4
  30. AAA
  31. ndc-mon2
  32. -------------------------------------------
  33. c1              Disk            ENABLED      Disk
  34. c3              GENESIS         ENABLED      USP4
  35. c4              GENESIS         ENABLED      USP4
  36. BBB
  37. ndc-mon3
  38. -------------------------------------------
  39. c2              AMS_WMS         ENABLED      AMS2
  40. c3              AMS_WMS         ENABLED      AMS2
  41. c3              TagmaStore-USP  ENABLED      USP4
  42. c2              TagmaStore-USP  ENABLED      USP4
  43. c1              Disk            ENABLED      disk
复制代码

作者: beacon1024   发布时间: 2011-07-22

你改了RS,匹配不到BBB了

作者: li2002   发布时间: 2011-07-22