标题: [文本处理] 请问怎么把上一次命令输出内容赋值给变量? [打印本页]
作者: linjuming 时间: 2009-8-18 16:44 标题: 请问怎么把上一次命令输出内容赋值给变量?
<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文件名- @echo off
- 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 编辑 ]
作者: tireless 时间: 2009-8-21 01:57
- @echo off
- set file="index.html"
-
- call :1 > temp.~
- move temp.~ %file%
- exit /b
-
- :1
- for /f "delims=" %%a in ('findstr /n .* %file%') do (
- set var=%%a
- setlocal enabledelayedexpansion
- if "!var:*:=!"=="</head>" (
- endlocal
- for /f "delims=" %%b in ('f %file% -r:"***:\w+\.css" -o:"k"') do (
- echo ^<link rel="stylesheet" type="text/css" href="cmspath/%%b" /^>
- )
- echo ^</head^>
- for /f "delims=:" %%c in ("%%a") do more +%%c %file%
- goto :eof
- ) else echo;!var:*:=!
- endlocal
- )
复制代码
作者: zqz0012005 时间: 2009-8-21 08:54 标题: 来个vbs
- sFile = "a.htm"
- set fso = CreateObject("Scripting.FilesystemObject")
- s = fso.OpenTextFile(sFile).ReadAll
- set regEx = new regExp
- regEx.Pattern = "^.*href=""?(/?(?:\w+/)+(\w+\.css)).*$"
- regEx.IgnoreCase = True
- regEx.Global = True
- regEx.Multiline = True
- Set Matches = regEx.Execute(s)
- For Each Match in Matches
- t = t & Replace( Match.Value, Match.SubMatches(0), _
- "cmspath/" & Match.SubMatches(1) ) & vbLf
- Next
- s = Replace(s, "</head>", t & "</head>")
- 'wsh.echo s
- fso.OpenTextFile("a2.htm",2,true).Write s
- '确认无误后可直接将"a2.htm"换成sFile
复制代码
http://www.bathome.net/forum-16-1.html
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |