标题: [文本处理] [已解决]求助批处理替换文本问题 [打印本页]
作者: lonron 时间: 2023-5-5 23:08 标题: [已解决]求助批处理替换文本问题
本帖最后由 lonron 于 2023-5-8 00:33 编辑
- Location: https://media-zjhz-fy-person.zj6oss.ctyunxs.cn/PERSONCLOUD/96992c80-baea-459e-8589-50b1de713c51.exe?x-amz-CLIENTTYPEIN=UNKNOWN&AWSAccessKeyId=0Lg7dAq3ZfHvePP8DKEU&x-amz-userLevel=0&x-amz-limitrate=50&x-amz-UID=300000229870059&x-amz-APPID=828221&response-content-disposition=attachment%3Bfilename%3D%22%E7%9F%AD%E9%93%BE%E5%A4%A7%E5%B8%88.exe%22%3Bfilename*%3DUTF-8%27%27%25E7%259F%25AD%25E9%2593%25BE%25E5%25A4%25A7%25E5%25B8%2588.exe&x-amz-CLIENTNETWORK=UNKNOWN&x-amz-CLOUDTYPEIN=PERSON&Signature=bpItQBSlrZ9hwiZF%2BzB8eokXzi4%3D&x-amz-SHID=1250015256399&Expires=1683296898&x-amz-FSIZE=600576&x-amz-UFID=32431164142952114
复制代码
将以上保存在 test.txt 内容中的 &x-amz-limitrate=50 删除
我用下面的这个方式没成功,不知道哪里写错了- @echo off
- setlocal enabledelayedexpansion
- for /f "delims=" %%i in (test.txt) do (
- set "var=%%i"
- set "var=!var:&x-amz-limitrate=50=!"
- )
- echo !var!
- pause
复制代码
在第一个=号前加了转义好像也无济于事
作者: czjt1234 时间: 2023-5-6 05:54
- rem 另存为 ANSI 编码
- ' & cls & cscript.exe /nologo /e:vbscript "%~f0" %* & pause & exit
-
- Dim oWshShell, oFSO, oStream, s
-
- Const file = "test.txt" '原文件。支持文件拖放,支持文件名作为命令行参数
- Const charset = "GBK" '文件编码。支持Unicode和UTF-8
-
- Set oWshShell = CreateObject("WScript.Shell")
- Set oFSO = CreateObject("Scripting.FileSystemObject")
- s = oFSO.GetParentFolderName(WScript.ScriptFullname)
- oWshShell.CurrentDirectory = s
-
- Set oStream = CreateObject("ADODB.Stream")
- oStream.Type = 2 'adTypeText
- oStream.Mode = 3 'adModeReadWrite
- oStream.Charset = charset
-
- If WScript.Arguments.Count > 0 Then
- For Each s In WScript.Arguments
- Call run(s)
- Next
- Else
- Call run(file)
- End If
-
- Sub run(ByVal file)
- Dim s
- oStream.Open()
- oStream.LoadFromFile file
- s = oStream.ReadText()
- oStream.Close()
- s = RePlace(s, "&x-amz-limitrate=50", "")
- WScript.Echo s
- End Sub
复制代码
作者: hfxiang 时间: 2023-5-7 17:07
回复 1# lonron
这种文本类的处置,俺大多数时候习惯于用gawk( http://bcn.bathome.net/tool/4.1.0/gawk.exe )- gawk "{gsub(/&x-amz-limitrate=50/,\"\")}1" test.txt>Out_test.txt
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |