[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 请问怎么把上一次命令输出内容赋值给变量?

<head>
<meta name="keywords" c />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="Bookmark" href="/favicon.ico" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <link rel="stylesheet" type="text/css" href="css/all.css" />
    <script src="files/jquery.js" type="text/javascript"></script>
    <script src="files/Public.js" type="text/javascript"></script>
    <script src="files/mall.js" type="text/javascript"></script>
    <script type="text/javascript">
</head>

--------------------------------------------------------------------------------
我使用 find 小工具进行正则匹配找到上面2个css文件名
  1. @echo off
  2. f index.html -r:"***:\w+\.css" -o:"k"
复制代码
我本来的想法是用 for 什么的把上面输出的结果,(但不知道怎么样操作上一条命令输出的结果。)
index.css
all.css
重新组合做成
    <link rel="stylesheet" type="text/css" href="cmspath/index.css" />
    <link rel="stylesheet" type="text/css" href="cmspath/all.css" />
然后添加到</head>的前面,即

---------------------------------------------------------------------------------
<head>
<meta name="keywords" c />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="Bookmark" href="/favicon.ico" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <link rel="stylesheet" type="text/css" href="css/all.css" />
    <script src="files/jquery.js" type="text/javascript"></script>
    <script src="files/Public.js" type="text/javascript"></script>
    <script src="files/mall.js" type="text/javascript"></script>
    <script type="text/javascript">
    <link rel="stylesheet" type="text/css" href="cmspath/index.css" />
    <link rel="stylesheet" type="text/css" href="cmspath/all.css" />
</head>
---------------------------------------------------------------------------

[ 本帖最后由 linjuming 于 2009-8-18 16:47 编辑 ]

  1. @echo off
  2. set file="index.html"
  3. call :1 > temp.~
  4. move temp.~ %file%
  5. exit /b
  6. :1
  7. for /f "delims=" %%a in ('findstr /n .* %file%') do (
  8.   set var=%%a
  9.   setlocal enabledelayedexpansion
  10.   if "!var:*:=!"=="</head>" (
  11.     endlocal
  12.     for /f "delims=" %%b in ('f %file% -r:"***:\w+\.css" -o:"k"') do (
  13.       echo    ^<link rel="stylesheet" type="text/css" href="cmspath/%%b" /^>
  14.     )
  15.     echo ^</head^>
  16.     for /f "delims=:" %%c in ("%%a") do more +%%c %file%
  17.     goto :eof
  18.   ) else echo;!var:*:=!
  19.   endlocal
  20. )
复制代码

TOP

来个vbs

  1. sFile = "a.htm"
  2. set fso = CreateObject("Scripting.FilesystemObject")
  3. s = fso.OpenTextFile(sFile).ReadAll
  4. set regEx = new regExp
  5. regEx.Pattern = "^.*href=""?(/?(?:\w+/)+(\w+\.css)).*$"
  6. regEx.IgnoreCase = True
  7. regEx.Global = True
  8. regEx.Multiline = True
  9. Set Matches = regEx.Execute(s)
  10. For Each Match in Matches
  11.     t = t & Replace( Match.Value, Match.SubMatches(0), _
  12.         "cmspath/" & Match.SubMatches(1) ) & vbLf
  13. Next
  14. s = Replace(s, "</head>", t & "</head>")
  15. 'wsh.echo s
  16. fso.OpenTextFile("a2.htm",2,true).Write s
  17. '确认无误后可直接将"a2.htm"换成sFile
复制代码
http://www.bathome.net/forum-16-1.html
命令行参考:hh.exe ntcmds.chm::/ntcmds.htm
求助者请拿出诚心,别人才愿意奉献热心!
把查看手册形成条件反射!

TOP

返回列表