Chinaunix

标题: [已解决]正则替换反向引用替换 vim中可以,sed (solaris版本)没工作 [打印本页]

作者: 可可火山    时间: 2012-01-04 16:53
标题: [已解决]正则替换反向引用替换 vim中可以,sed (solaris版本)没工作
本帖最后由 可可火山 于 2012-01-04 18:01 编辑

我开始的正则命令
"s/\^(${CHECKING_USER}.*${CHECKING_FINGERPIRNT}.*|\).*$/\1${WORKING_DATE}/g"
正确的正则命令
"s/^\(${CHECKING_USER}.*${CHECKING_FINGERPIRNT}.*|\).*$/\1${WORKING_DATE}/g"
匹配行首的^不需要放在反向引用的括号中。
Thanks to Shell_HAT.

我一个SSHD日志分析脚本,需要根据每天的日志记录下那些SSH key的最后使用时间
下面input.file测试文件Key是一样的,不过就想演示下替换已经有最后一天使用记录和没有记录的日期更新下。
  1. [user@SSH_KEY_FINGERPRINT (0)]$cat input.file
  2. account|/home/account/.ssh/authorized_keys2|LINE2|a8:10:9b:ff:ff:ff:5f:dc:02:50:9d:2c:22:be:ee:ee|Hello on platform |from="remote.host.com" ssh-dss AAAAB3NzaC1kc3MAAAEBAIWrZa2od1PF2zvwTNeDg+p2sb46/rOh0FWBxUqM9PO2wvmBreakthekeynPlDcmY3cQclJDEOFUQMkXRUa1TgTrt338vdds9HkwBreaktheKey4edj6hfviF0TbfdNEDPAap1CVIQdJe37CcLVBreakTheKeyfKvSmhtSWTqjVv2kUNX5DvWGWimc9vW5hNdAaT/X7aIERZmLrl9NGjQ2qe3HYJXRy7scvTdH92gQCxP6+NWeneAHYZNqV9GxfaS5r6Mvau9L+th/it90x2ulnotworkingkeyA8BoJD/ASBRZR20+pnaTllGQwjpS8Kz4WCCsVhi6gGi1E7oSYrSkAAAAVAPeeZjOCWI9+YTOsmm9434IJRJIrAAABADyKD8xmwNcZzXfxXWf//wvixpPRfP7W51rHjQcvbNgLQDt6uc1wCGP29YCz96j59LuIxmDPBpzHjvY2eFv+EHPNKDPB24Jn7CbwxNh/h2E5MdU2Ipu8Mq9vtxrIugy9HlKUvPY/r35PiqDOvIXs7lv//S/NE4RErZ7+y6VhdpAYJZtuMYTHq6OEg0lVGNZtKsEb40+gKjdAVsbpd95pxlyBzCdeVYWF0PsOwC5Vqjdid4yO2wPvr/I+Q3ULLLVpvNpE3QquNT2I8ZFXTVvxKA9jTBpyJDjDiYX+xkSCzmJ5SR9vq3cSTbp24ONmRyV7grg0Adkv9q2yXIaJZN2SawAAAAEAOVlDx+GzVr/8Tc4RGzneetP6WSs+S4+bYqDpJiXF8i6L3Eg6l0jIxjGSuR1C2pMylN74DzX14rOyal+u0hQ7836HaGZ1Hg8Yq/0r3hHLmRWTU4Fmw24Ri9qNg9uFikh3Z21QfVzu2hvyn3CMpDBv+UY977bmeWAaADo/IIaFA0jNQFiJgZPCG36e5lGsaIldePAc4Z6GhKIFWFIPEyDFxXpm6xGKeh8GchquxqTHvnz4NQceOOz6pGnjOb8hL+YQhDjqOY5Dfo2O2gZgDNLt/dO6NCPO+Wgx3FDu+44pZCUlEI0ZTFpA531Kl1k/P91DARmAgQiqE/ZZOp8k8Mj2rA== Hello on platform|20110101
  3. account|/home/account/.ssh/authorized_keys2|LINE2|a8:10:9b:ff:ff:ff:5f:dc:02:50:9d:2c:22:be:ee:ee|Hello on platform |from="remote.host.com" ssh-dss AAAAB3NzaC1kc3MAAAEBAIWrZa2od1PF2zvwTNeDg+p2sb46/rOh0FWBxUqM9PO2wvmBreakthekeynPlDcmY3cQclJDEOFUQMkXRUa1TgTrt338vdds9HkwBreaktheKey4edj6hfviF0TbfdNEDPAap1CVIQdJe37CcLVBreakTheKeyfKvSmhtSWTqjVv2kUNX5DvWGWimc9vW5hNdAaT/X7aIERZmLrl9NGjQ2qe3HYJXRy7scvTdH92gQCxP6+NWeneAHYZNqV9GxfaS5r6Mvau9L+th/it90x2ulnotworkingkeyA8BoJD/ASBRZR20+pnaTllGQwjpS8Kz4WCCsVhi6gGi1E7oSYrSkAAAAVAPeeZjOCWI9+YTOsmm9434IJRJIrAAABADyKD8xmwNcZzXfxXWf//wvixpPRfP7W51rHjQcvbNgLQDt6uc1wCGP29YCz96j59LuIxmDPBpzHjvY2eFv+EHPNKDPB24Jn7CbwxNh/h2E5MdU2Ipu8Mq9vtxrIugy9HlKUvPY/r35PiqDOvIXs7lv//S/NE4RErZ7+y6VhdpAYJZtuMYTHq6OEg0lVGNZtKsEb40+gKjdAVsbpd95pxlyBzCdeVYWF0PsOwC5Vqjdid4yO2wPvr/I+Q3ULLLVpvNpE3QquNT2I8ZFXTVvxKA9jTBpyJDjDiYX+xkSCzmJ5SR9vq3cSTbp24ONmRyV7grg0Adkv9q2yXIaJZN2SawAAAAEAOVlDx+GzVr/8Tc4RGzneetP6WSs+S4+bYqDpJiXF8i6L3Eg6l0jIxjGSuR1C2pMylN74DzX14rOyal+u0hQ7836HaGZ1Hg8Yq/0r3hHLmRWTU4Fmw24Ri9qNg9uFikh3Z21QfVzu2hvyn3CMpDBv+UY977bmeWAaADo/IIaFA0jNQFiJgZPCG36e5lGsaIldePAc4Z6GhKIFWFIPEyDFxXpm6xGKeh8GchquxqTHvnz4NQceOOz6pGnjOb8hL+YQhDjqOY5Dfo2O2gZgDNLt/dO6NCPO+Wgx3FDu+44pZCUlEI0ZTFpA531Kl1k/P91DARmAgQiqE/ZZOp8k8Mj2rA== Hello on platform|
  4. [user@SSH_KEY_FINGERPRINT (0)]$CHECKING_USER="account"
  5. [user@SSH_KEY_FINGERPRINT (0)]$CHECKING_FINGERPIRNT="a8:10:9b:ff:ff:ff:5f:dc:02:50:9d:2c:22:be:ee:ee"
  6. [user@SSH_KEY_FINGERPRINT (0)]$WORKING_DATE="20120104"
  7. [user@SSH_KEY_FINGERPRINT (0)]$/usr/bin/sed "s/\(^${CHECKING_USER}.*$CHECKING_FINGERPIRNT.*|\).*$/\1${WORKING_DATE}/g" input.file > output.file
  8. [user@SSH_KEY_FINGERPRINT (0)]$diff input.file  output.file
  9. [user@SSH_KEY_FINGERPRINT (0)]$/usr/ucb/sed "s/\(^${CHECKING_USER}.*$CHECKING_FINGERPIRNT.*|\).*$/\1${WORKING_DATE}/g" input.file > output.file
  10. [user@SSH_KEY_FINGERPRINT (0)]$diff input.file  output.file
  11. [user@SSH_KEY_FINGERPRINT (0)]$
  12. [user@SSH_KEY_FINGERPRINT (0)]$set -x
  13. [user@SSH_KEY_FINGERPRINT (0)]$sed "s/\(^${CHECKING_USER}.*$CHECKING_FINGERPIRNT.*|\).*$/\1${WORKING_DATE}/g" input.file > output.file
  14. + sed 's/\(^account.*a8:10:9b:ff:ff:ff:5f:dc:02:50:9d:2c:22:be:ee:ee.*|\).*$/\120120104/g' input.file
  15. [user@SSH_KEY_FINGERPRINT (0)]$set +x
  16. + set +x
  17. [user@SSH_KEY_FINGERPRINT (0)]$diff input.file  output.file
  18. [user@SSH_KEY_FINGERPRINT (0)]$
复制代码
关键的正则命令
's/\(^account.*a8:10:9b:ff:ff:ff:5f:dc:02:50:9d:2c:22:be:ee:ee.*|\).*$/\120120104/g'
在vim中是可以工作的,但是 sed命令不行,系统是solaris 10. /usr/bin/sed和/usr/ucb/sed都不行


相同的命令我在CentOS上跑了下可以的,现在看起来就是solaris下不行。

作者: Shell_HAT    时间: 2012-01-04 17:12
/usr/xpg4/bin/sed行吗?
作者: 可可火山    时间: 2012-01-04 17:26
回复 2# Shell_HAT


    谢谢提醒,可是好像也不行,我找了下所有的sed命令好像都不行。
  1. [user@SSH_KEY_FINGERPRINT (0)]$/usr/xpg4/bin/sed 's/\(^account.*a8:10:9b:ff:ff:ff:5f:dc:02:50:9d:2c:22:be:ee:ee.*|\).*$/\120120104/g' input.file
  2. account|/home/account/.ssh/authorized_keys2|LINE2|a8:10:9b:ff:ff:ff:5f:dc:02:50:9d:2c:22:be:ee:ee|Hello on platform |from="remote.host.com" ssh-dss AAAAB3NzaC1kc3MAAAEBAIWrZa2od1PF2zvwTNeDg+p2sb46/rOh0FWBxUqM9PO2wvmBreakthekeynPlDcmY3cQclJDEOFUQMkXRUa1TgTrt338vdds9HkwBreaktheKey4edj6hfviF0TbfdNEDPAap1CVIQdJe37CcLVBreakTheKeyfKvSmhtSWTqjVv2kUNX5DvWGWimc9vW5hNdAaT/X7aIERZmLrl9NGjQ2qe3HYJXRy7scvTdH92gQCxP6+NWeneAHYZNqV9GxfaS5r6Mvau9L+th/it90x2ulnotworkingkeyA8BoJD/ASBRZR20+pnaTllGQwjpS8Kz4WCCsVhi6gGi1E7oSYrSkAAAAVAPeeZjOCWI9+YTOsmm9434IJRJIrAAABADyKD8xmwNcZzXfxXWf//wvixpPRfP7W51rHjQcvbNgLQDt6uc1wCGP29YCz96j59LuIxmDPBpzHjvY2eFv+EHPNKDPB24Jn7CbwxNh/h2E5MdU2Ipu8Mq9vtxrIugy9HlKUvPY/r35PiqDOvIXs7lv//S/NE4RErZ7+y6VhdpAYJZtuMYTHq6OEg0lVGNZtKsEb40+gKjdAVsbpd95pxlyBzCdeVYWF0PsOwC5Vqjdid4yO2wPvr/I+Q3ULLLVpvNpE3QquNT2I8ZFXTVvxKA9jTBpyJDjDiYX+xkSCzmJ5SR9vq3cSTbp24ONmRyV7grg0Adkv9q2yXIaJZN2SawAAAAEAOVlDx+GzVr/8Tc4RGzneetP6WSs+S4+bYqDpJiXF8i6L3Eg6l0jIxjGSuR1C2pMylN74DzX14rOyal+u0hQ7836HaGZ1Hg8Yq/0r3hHLmRWTU4Fmw24Ri9qNg9uFikh3Z21QfVzu2hvyn3CMpDBv+UY977bmeWAaADo/IIaFA0jNQFiJgZPCG36e5lGsaIldePAc4Z6GhKIFWFIPEyDFxXpm6xGKeh8GchquxqTHvnz4NQceOOz6pGnjOb8hL+YQhDjqOY5Dfo2O2gZgDNLt/dO6NCPO+Wgx3FDu+44pZCUlEI0ZTFpA531Kl1k/P91DARmAgQiqE/ZZOp8k8Mj2rA== Hello on platform|20120101
  3. account|/home/account/.ssh/authorized_keys2|LINE2|a8:10:9b:ff:ff:ff:5f:dc:02:50:9d:2c:22:be:ee:ee|Hello on platform |from="remote.host.com" ssh-dss AAAAB3NzaC1kc3MAAAEBAIWrZa2od1PF2zvwTNeDg+p2sb46/rOh0FWBxUqM9PO2wvmBreakthekeynPlDcmY3cQclJDEOFUQMkXRUa1TgTrt338vdds9HkwBreaktheKey4edj6hfviF0TbfdNEDPAap1CVIQdJe37CcLVBreakTheKeyfKvSmhtSWTqjVv2kUNX5DvWGWimc9vW5hNdAaT/X7aIERZmLrl9NGjQ2qe3HYJXRy7scvTdH92gQCxP6+NWeneAHYZNqV9GxfaS5r6Mvau9L+th/it90x2ulnotworkingkeyA8BoJD/ASBRZR20+pnaTllGQwjpS8Kz4WCCsVhi6gGi1E7oSYrSkAAAAVAPeeZjOCWI9+YTOsmm9434IJRJIrAAABADyKD8xmwNcZzXfxXWf//wvixpPRfP7W51rHjQcvbNgLQDt6uc1wCGP29YCz96j59LuIxmDPBpzHjvY2eFv+EHPNKDPB24Jn7CbwxNh/h2E5MdU2Ipu8Mq9vtxrIugy9HlKUvPY/r35PiqDOvIXs7lv//S/NE4RErZ7+y6VhdpAYJZtuMYTHq6OEg0lVGNZtKsEb40+gKjdAVsbpd95pxlyBzCdeVYWF0PsOwC5Vqjdid4yO2wPvr/I+Q3ULLLVpvNpE3QquNT2I8ZFXTVvxKA9jTBpyJDjDiYX+xkSCzmJ5SR9vq3cSTbp24ONmRyV7grg0Adkv9q2yXIaJZN2SawAAAAEAOVlDx+GzVr/8Tc4RGzneetP6WSs+S4+bYqDpJiXF8i6L3Eg6l0jIxjGSuR1C2pMylN74DzX14rOyal+u0hQ7836HaGZ1Hg8Yq/0r3hHLmRWTU4Fmw24Ri9qNg9uFikh3Z21QfVzu2hvyn3CMpDBv+UY977bmeWAaADo/IIaFA0jNQFiJgZPCG36e5lGsaIldePAc4Z6GhKIFWFIPEyDFxXpm6xGKeh8GchquxqTHvnz4NQceOOz6pGnjOb8hL+YQhDjqOY5Dfo2O2gZgDNLt/dO6NCPO+Wgx3FDu+44pZCUlEI0ZTFpA531Kl1k/P91DARmAgQiqE/ZZOp8k8Mj2rA== Hello on platform|
复制代码
顺便放上centos下的测试,注意到sed是4.2.1的,看到sunfreeware站有最新sed源代码,我想去尝试编译下看看。
  1. [user@centos6 sedtest (0)]$ sed --version
  2. GNU sed version 4.2.1
  3. Copyright (C) 2009 Free Software Foundation, Inc.
  4. This is free software; see the source for copying conditions.  There is NO
  5. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
  6. to the extent permitted by law.

  7. GNU sed home page: <http://www.gnu.org/software/sed/>.
  8. General help using GNU software: <http://www.gnu.org/gethelp/>.
  9. E-mail bug reports to: <bug-gnu-utils@gnu.org>.
  10. Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
  11. [user@centos6 sedtest (0)]$ cat input.file
  12. account|/home/account/.ssh/authorized_keys2|LINE2|a8:10:9b:ff:ff:ff:5f:dc:02:50:9d:2c:22:be:ee:ee|Hello on platform |from="remote.host.com" ssh-dss AAAAB3NzaC1kc3MAAAEBAIWrZa2od1PF2zvwTNeDg+p2sb46/rOh0FWBxUqM9PO2wvmBreakthekeynPlDcmY3cQclJDEOFUQMkXRUa1TgTrt338vdds9HkwBreaktheKey4edj6hfviF0TbfdNEDPAap1CVIQdJe37CcLVBreakTheKeyfKvSmhtSWTqjVv2kUNX5DvWGWimc9vW5hNdAaT/X7aIERZmLrl9NGjQ2qe3HYJXRy7scvTdH92gQCxP6+NWeneAHYZNqV9GxfaS5r6Mvau9L+th/it90x2ulnotworkingkeyA8BoJD/ASBRZR20+pnaTllGQwjpS8Kz4WCCsVhi6gGi1E7oSYrSkAAAAVAPeeZjOCWI9+YTOsmm9434IJRJIrAAABADyKD8xmwNcZzXfxXWf//wvixpPRfP7W51rHjQcvbNgLQDt6uc1wCGP29YCz96j59LuIxmDPBpzHjvY2eFv+EHPNKDPB24Jn7CbwxNh/h2E5MdU2Ipu8Mq9vtxrIugy9HlKUvPY/r35PiqDOvIXs7lv//S/NE4RErZ7+y6VhdpAYJZtuMYTHq6OEg0lVGNZtKsEb40+gKjdAVsbpd95pxlyBzCdeVYWF0PsOwC5Vqjdid4yO2wPvr/I+Q3ULLLVpvNpE3QquNT2I8ZFXTVvxKA9jTBpyJDjDiYX+xkSCzmJ5SR9vq3cSTbp24ONmRyV7grg0Adkv9q2yXIaJZN2SawAAAAEAOVlDx+GzVr/8Tc4RGzneetP6WSs+S4+bYqDpJiXF8i6L3Eg6l0jIxjGSuR1C2pMylN74DzX14rOyal+u0hQ7836HaGZ1Hg8Yq/0r3hHLmRWTU4Fmw24Ri9qNg9uFikh3Z21QfVzu2hvyn3CMpDBv+UY977bmeWAaADo/IIaFA0jNQFiJgZPCG36e5lGsaIldePAc4Z6GhKIFWFIPEyDFxXpm6xGKeh8GchquxqTHvnz4NQceOOz6pGnjOb8hL+YQhDjqOY5Dfo2O2gZgDNLt/dO6NCPO+Wgx3FDu+44pZCUlEI0ZTFpA531Kl1k/P91DARmAgQiqE/ZZOp8k8Mj2rA== Hello on platform|20110101
  13. account|/home/account/.ssh/authorized_keys2|LINE2|a8:10:9b:ff:ff:ff:5f:dc:02:50:9d:2c:22:be:ee:ee|Hello on platform |from="remote.host.com" ssh-dss AAAAB3NzaC1kc3MAAAEBAIWrZa2od1PF2zvwTNeDg+p2sb46/rOh0FWBxUqM9PO2wvmBreakthekeynPlDcmY3cQclJDEOFUQMkXRUa1TgTrt338vdds9HkwBreaktheKey4edj6hfviF0TbfdNEDPAap1CVIQdJe37CcLVBreakTheKeyfKvSmhtSWTqjVv2kUNX5DvWGWimc9vW5hNdAaT/X7aIERZmLrl9NGjQ2qe3HYJXRy7scvTdH92gQCxP6+NWeneAHYZNqV9GxfaS5r6Mvau9L+th/it90x2ulnotworkingkeyA8BoJD/ASBRZR20+pnaTllGQwjpS8Kz4WCCsVhi6gGi1E7oSYrSkAAAAVAPeeZjOCWI9+YTOsmm9434IJRJIrAAABADyKD8xmwNcZzXfxXWf//wvixpPRfP7W51rHjQcvbNgLQDt6uc1wCGP29YCz96j59LuIxmDPBpzHjvY2eFv+EHPNKDPB24Jn7CbwxNh/h2E5MdU2Ipu8Mq9vtxrIugy9HlKUvPY/r35PiqDOvIXs7lv//S/NE4RErZ7+y6VhdpAYJZtuMYTHq6OEg0lVGNZtKsEb40+gKjdAVsbpd95pxlyBzCdeVYWF0PsOwC5Vqjdid4yO2wPvr/I+Q3ULLLVpvNpE3QquNT2I8ZFXTVvxKA9jTBpyJDjDiYX+xkSCzmJ5SR9vq3cSTbp24ONmRyV7grg0Adkv9q2yXIaJZN2SawAAAAEAOVlDx+GzVr/8Tc4RGzneetP6WSs+S4+bYqDpJiXF8i6L3Eg6l0jIxjGSuR1C2pMylN74DzX14rOyal+u0hQ7836HaGZ1Hg8Yq/0r3hHLmRWTU4Fmw24Ri9qNg9uFikh3Z21QfVzu2hvyn3CMpDBv+UY977bmeWAaADo/IIaFA0jNQFiJgZPCG36e5lGsaIldePAc4Z6GhKIFWFIPEyDFxXpm6xGKeh8GchquxqTHvnz4NQceOOz6pGnjOb8hL+YQhDjqOY5Dfo2O2gZgDNLt/dO6NCPO+Wgx3FDu+44pZCUlEI0ZTFpA531Kl1k/P91DARmAgQiqE/ZZOp8k8Mj2rA== Hello on platform|
  14. [user@centos6 sedtest (0)]$
  15. [user@centos6 sedtest (0)]$ sed 's/\(^account.*a8:10:9b:ff:ff:ff:5f:dc:02:50:9d:2c:22:be:ee:ee.*|\).*$/\120120104/g' input.file
  16. account|/home/account/.ssh/authorized_keys2|LINE2|a8:10:9b:ff:ff:ff:5f:dc:02:50:9d:2c:22:be:ee:ee|Hello on platform |from="remote.host.com" ssh-dss AAAAB3NzaC1kc3MAAAEBAIWrZa2od1PF2zvwTNeDg+p2sb46/rOh0FWBxUqM9PO2wvmBreakthekeynPlDcmY3cQclJDEOFUQMkXRUa1TgTrt338vdds9HkwBreaktheKey4edj6hfviF0TbfdNEDPAap1CVIQdJe37CcLVBreakTheKeyfKvSmhtSWTqjVv2kUNX5DvWGWimc9vW5hNdAaT/X7aIERZmLrl9NGjQ2qe3HYJXRy7scvTdH92gQCxP6+NWeneAHYZNqV9GxfaS5r6Mvau9L+th/it90x2ulnotworkingkeyA8BoJD/ASBRZR20+pnaTllGQwjpS8Kz4WCCsVhi6gGi1E7oSYrSkAAAAVAPeeZjOCWI9+YTOsmm9434IJRJIrAAABADyKD8xmwNcZzXfxXWf//wvixpPRfP7W51rHjQcvbNgLQDt6uc1wCGP29YCz96j59LuIxmDPBpzHjvY2eFv+EHPNKDPB24Jn7CbwxNh/h2E5MdU2Ipu8Mq9vtxrIugy9HlKUvPY/r35PiqDOvIXs7lv//S/NE4RErZ7+y6VhdpAYJZtuMYTHq6OEg0lVGNZtKsEb40+gKjdAVsbpd95pxlyBzCdeVYWF0PsOwC5Vqjdid4yO2wPvr/I+Q3ULLLVpvNpE3QquNT2I8ZFXTVvxKA9jTBpyJDjDiYX+xkSCzmJ5SR9vq3cSTbp24ONmRyV7grg0Adkv9q2yXIaJZN2SawAAAAEAOVlDx+GzVr/8Tc4RGzneetP6WSs+S4+bYqDpJiXF8i6L3Eg6l0jIxjGSuR1C2pMylN74DzX14rOyal+u0hQ7836HaGZ1Hg8Yq/0r3hHLmRWTU4Fmw24Ri9qNg9uFikh3Z21QfVzu2hvyn3CMpDBv+UY977bmeWAaADo/IIaFA0jNQFiJgZPCG36e5lGsaIldePAc4Z6GhKIFWFIPEyDFxXpm6xGKeh8GchquxqTHvnz4NQceOOz6pGnjOb8hL+YQhDjqOY5Dfo2O2gZgDNLt/dO6NCPO+Wgx3FDu+44pZCUlEI0ZTFpA531Kl1k/P91DARmAgQiqE/ZZOp8k8Mj2rA== Hello on platform|20120104
  17. account|/home/account/.ssh/authorized_keys2|LINE2|a8:10:9b:ff:ff:ff:5f:dc:02:50:9d:2c:22:be:ee:ee|Hello on platform |from="remote.host.com" ssh-dss AAAAB3NzaC1kc3MAAAEBAIWrZa2od1PF2zvwTNeDg+p2sb46/rOh0FWBxUqM9PO2wvmBreakthekeynPlDcmY3cQclJDEOFUQMkXRUa1TgTrt338vdds9HkwBreaktheKey4edj6hfviF0TbfdNEDPAap1CVIQdJe37CcLVBreakTheKeyfKvSmhtSWTqjVv2kUNX5DvWGWimc9vW5hNdAaT/X7aIERZmLrl9NGjQ2qe3HYJXRy7scvTdH92gQCxP6+NWeneAHYZNqV9GxfaS5r6Mvau9L+th/it90x2ulnotworkingkeyA8BoJD/ASBRZR20+pnaTllGQwjpS8Kz4WCCsVhi6gGi1E7oSYrSkAAAAVAPeeZjOCWI9+YTOsmm9434IJRJIrAAABADyKD8xmwNcZzXfxXWf//wvixpPRfP7W51rHjQcvbNgLQDt6uc1wCGP29YCz96j59LuIxmDPBpzHjvY2eFv+EHPNKDPB24Jn7CbwxNh/h2E5MdU2Ipu8Mq9vtxrIugy9HlKUvPY/r35PiqDOvIXs7lv//S/NE4RErZ7+y6VhdpAYJZtuMYTHq6OEg0lVGNZtKsEb40+gKjdAVsbpd95pxlyBzCdeVYWF0PsOwC5Vqjdid4yO2wPvr/I+Q3ULLLVpvNpE3QquNT2I8ZFXTVvxKA9jTBpyJDjDiYX+xkSCzmJ5SR9vq3cSTbp24ONmRyV7grg0Adkv9q2yXIaJZN2SawAAAAEAOVlDx+GzVr/8Tc4RGzneetP6WSs+S4+bYqDpJiXF8i6L3Eg6l0jIxjGSuR1C2pMylN74DzX14rOyal+u0hQ7836HaGZ1Hg8Yq/0r3hHLmRWTU4Fmw24Ri9qNg9uFikh3Z21QfVzu2hvyn3CMpDBv+UY977bmeWAaADo/IIaFA0jNQFiJgZPCG36e5lGsaIldePAc4Z6GhKIFWFIPEyDFxXpm6xGKeh8GchquxqTHvnz4NQceOOz6pGnjOb8hL+YQhDjqOY5Dfo2O2gZgDNLt/dO6NCPO+Wgx3FDu+44pZCUlEI0ZTFpA531Kl1k/P91DARmAgQiqE/ZZOp8k8Mj2rA== Hello on platform|20120104
复制代码

作者: Shell_HAT    时间: 2012-01-04 17:39
  1. /usr/xpg4/bin/sed "s/^\(${CHECKING_USER}.*${CHECKING_FINGERPIRNT}.*|\).*$/\1${WORKING_DATE}/g" urfile
复制代码

作者: 可可火山    时间: 2012-01-04 17:51
回复 4# Shell_HAT

  
赞。

原来还是我的正则写错了,行首^符号不应该放在反向引用的括号中。

PS:我在solaris上装了sed 4.2.1后,原来以为“正确的”正则也能跑了,不过这样脚本还是只能在那台服务器上跑。
再谢你的帮助~
   
作者: yangkyo821    时间: 2012-01-04 18:23
不懂什么是反向引用
作者: Shell_HAT    时间: 2012-01-04 19:26
回复 6# yangkyo821


Regular Expression 简介
http://bbs.chinaunix.net/thread-605570-1-1.html
作者: yangkyo821    时间: 2012-01-04 19:34
回复 7# Shell_HAT
我会正则,只是没听说过反向引用
作者: 可可火山    时间: 2012-01-04 19:54
反向引用 就是 backreference, 应该就是正则的一个概念。

参见《精通正则表达式》 Page 21 等等



作者: yangkyo821    时间: 2012-01-04 19:58
回复 9# 可可火山


    原来是backreference,明白了




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2