Board logo

标题: [文本处理] 批处理如何将文本中的指定字符串替换为批处理所在当前目录路径 [打印本页]

作者: cctvmtv    时间: 2008-9-21 16:21     标题: 批处理如何将文本中的指定字符串替换为批处理所在当前目录路径

本帖最后由 pcl_test 于 2016-11-16 23:59 编辑

想用批处理替换当前目录下的httpd.conf 文件里的 ServerRoot "C:/apache" 这句。替换为每次运行此批处理自动改变serverroot 目录为当前绝对路径 也就是替换为%cd%的绝对路径

这个批处理怎么写?
作者: Batcher    时间: 2008-9-21 16:41

  1. @echo off
  2. set curpath=%cd:\=\\%
  3. sed "s/ServerRoot \".*\"/ServerRoot \"%curpath%\"/" "httpd.conf">a.txt
  4. move /y a.txt httpd.conf
复制代码
sed.exe
http://bbs.bathome.net/attachment.php?aid=220
作者: cctvmtv    时间: 2008-9-21 19:51

能不能解释一下。
还有sed的用法
作者: Batcher    时间: 2008-9-21 20:37     标题: 回复 3楼 的帖子

sed文章收集
http://bbs.bathome.net/thread-1929-1-1.html

[ 本帖最后由 Batcher 于 2008-9-21 20:51 编辑 ]
作者: cctvmtv    时间: 2008-9-21 22:14

原帖由 Batcher 于 2008-9-21 16:41 发表
@echo off
set curpath=%cd:\=\\%
sed "s/ServerRoot \".*\"/ServerRoot \"%curpath%\"/" "httpd.conf">a.txt
move /y a.txt httpd.confsed.exe
http://bbs.bathome.net/attachment.php?aid=220


上面命令得到的是 ServerRoot "X:\xx\xx" apache配置文件路径不能使用 \     可以使用 \\ 或 /  又怎么写呢?
作者: Batcher    时间: 2008-9-21 22:29     标题: 回复 5楼 的帖子

  1. @echo off
  2. set curpath=%cd:\=\/%
  3. sed "s/ServerRoot \".*\"/ServerRoot \"%curpath%\"/" "httpd.conf">a.txt
  4. move /y a.txt httpd.conf
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2