标题: [文本处理] 批处理替换文本指定字符串问题 [打印本页]
作者: heshibin 时间: 2015-11-8 20:59 标题: 批处理替换文本指定字符串问题
{"AlignCell":true,"AutoSort":false,"BlackTagIconList":[{"Type":"sysIcon","name":"呼叫服务.lnk"},{"Type":"sysIcon","name":"商品超市.lnk"}],"IconCellid":"","IconList":[{"Type":"sysIcon","bottom":440,"left":10,"name":"英雄联盟TGP.lnk","right":110,"top":340},{"Type":"sysIcon","bottom":240,"left":10,"name":"网吧专用.lnk","right":110,"top":140},{"Type":"sysIcon","bottom":340,"left":10,"name":"腾讯QQ.lnk","right":110,"top":240},{"Type":"sysIcon","bottom":140,"left":10,"name":"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}","right":110,"top":40},{"Type":"sysIcon","bottom":540,"left":10,"name":"侠盗列车5.lnk","right":110,"top":440},{"Type":"sysIcon","bottom":640,"left":10,"name":"挂机锁.lnk","right":110,"top":540},{"Type":"sysIcon","bottom":740,"left":10,"name":"用户中心.lnk","right":110,"top":640},{"Type":"sysIcon","bottom":840,"left":10,"name":"自助结账.lnk","right":110,"top":740}],"IconSize":2,"WallpaperType":0,"WhiteIconList":[{"Type":"sysIcon","name":"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"},{"Type":"sysIcon","name":"侠盗列车5.lnk"},{"Type":"sysIcon","name":"用户中心.lnk"},{"Type":"sysIcon","name":"网吧专用.lnk"},{"Type":"sysIcon","name":"自助结账.lnk"},{"Type":"sysIcon","name":"英雄联盟TGP.lnk"}]}
以上是批处理一个文本内容 我的目的就是提取"WallpaperType":0 后面的0是可变的 无论怎么变都是要替换成"WallpaperType":0
作者: Batcher 时间: 2015-11-8 21:15
- sed -r "s/(\"WallpaperType\":)[^,]+,/\10,/" 1.txt > 2.txt
复制代码
作者: /zhqsystem/zhq 时间: 2015-11-9 00:52
终于编好了,楼主测试吧- @echo off
- setlocal enabledelayedexpansion
- for /f "delims=" %%i in ('type "%~dp0\1.txt"') do (
- for %%j in (%%i) do (
- for /f "tokens=1,* delims=:" %%k in ("%%j") do (
- if /i "%%~k"=="WallpaperType" (
- set "name=!name!,"%%~k":0"
- ) else (
- if defined name set "name=!name!,%%j"
- if not defined name set "name=%%j"
- )
- )
- )
- )
- (echo=!name!)>2.txt
- pause
复制代码
作者: CrLf 时间: 2015-11-9 01:07
既然是 JSON,那用 JS 最方便了的:- <!-- :
- @echo off
- mshta "%~f0" <转换前.txt >转换后.txt
- exit
- -->
- <script src=http://www.bathome.net/lib/diy/hide.js></script>
- <script src=http://www.bathome.net/lib/diy/WSH.js></script>
- <script src=http://www.bathome.net/lib/json2.js></script>
- <script>
- var json = JSON.parse(WSH.StdIn.ReadAll())
- json.WallpaperType = 0
- WSH.Echo(JSON.stringify(json))
- </script>
复制代码
作者: 依山居 时间: 2015-11-9 02:47
- @echo off
- ::依山居 1:54 2015/11/9
-
- ::fr修改WallpaperType
- ::http://www.bathome.net/thread-38056-1-1.html
-
- ::fr是一个完整支持正则表达式查找替换的命令行工具,
- ::作者网站:http://baiy.cn/utils/fr/index.htm
-
- ::去掉-stdout参数则直接修改原文件
-
- ::直接修改原文件
- fr -r:"\"WallpaperType\":\d+," -t:"\"WallpaperType\":1," -trc x.json
-
-
- ::修改的内容,原文件不修改,重定向输出到新文件。
- fr -r:"\"WallpaperType\":\d+," -t:"\"WallpaperType\":1," -stdout -trc x.json>test.txt
-
- pause
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |