标题: [文本处理] 批处理怎样进行特殊符号和数字的替换? [打印本页]
作者: ritech 时间: 2010-5-28 15:36 标题: 批处理怎样进行特殊符号和数字的替换?
本帖最后由 pcl_test 于 2017-6-8 20:59 编辑
之前一直用SED在做,不过由于编码问题,sed改了后很多乱码,现在想用批处理实施
文本文件如下
80,"frame_0080.png",1,"gif","15",,,,,"000000",1,1,0,-159,-25,489,489,,6,0,"",0,,,,
81,"frame_0081.png",1,"gif","115",,,,,"000000",1,1,0,-100,-42,459,459,,6,0,"",0,,,,
82,"frame_0082.png",1,"gif","135",,,,,"000000",1,1,0,-163,-70,758,758,,6,0,"",0,,,,
83,"frame_0083.png",1,"gif","175",,,,,"000000",1,1,0,-217,-63,616,616,,6,0,"",0,,,,
84,"frame_0084.png",1,"gif","108",,,,,"000000",2,1,3,568,-176,666,666,,6,0,"",0,,,,
84,"frame_0084.png",1,"gif","215",,,,,"000000",2,2,7,0,-176,666,666,,6,0,"",0,,,,
1. 如何将包含 "frame_0082.png" 这行的行内容,复制并插入到最末尾一行?
2. 如何将"gif","215" (前面的215是变量) 但凡是小于256的变量统一替换为"gif","15"
作者: hanyeguxing 时间: 2010-5-28 16:51
本帖最后由 pcl_test 于 2017-6-8 20:59 编辑
运行前先备份原始文件:- @echo off&chcp 437 >nul&Graftabl 936 >nul
- (for /F "tokens=1-5* delims=," %%a in ('type "1.txt"^|more') do (
- set "a=%%a,%%b,%%c,%%d,"&set "e=%%e"&set "f=,,,,,%%f"
- setlocal enabledelayedexpansion
- if !e:~1^,-1! lss 256 set e="15"
- echo.!a!!e!!f!
- Endlocal))>$
- move $ 1.txt
复制代码
[ 本帖最后由 hanyeguxing 于 2010-5-28 16:53 编辑 ]
作者: CUer 时间: 2010-5-28 16:57
原始文件是什么编码格式?
哪个版本的sed?
你写的sed命令是什么?
作者: ritech 时间: 2010-5-28 17:34
sed -e "/\"256\"\,\"05\"\,\"F\"\,0\.5\,1\,\"000000\"\,1\,1\,/h" -e "$G" "%%i" > "%%i_"
这是复制到最后一行
sed "/\"gif\"\,\"256\"/!s/\"gif\"\,\"[0-9][0-9]\"/\"gif\"\,\"15\"/g" "%%i" > "%%i_"
sed "/\"gif\"\,\"256\"/!s/\"gif\"\,\"[0-9][0-9][0-9]\"/\"gif\"\,\"15\"/g" "%%i" > "%%i_"
上面的意思是不包含256的全部改成15
作者: ritech 时间: 2010-5-28 17:46
原帖由 hanyeguxing 于 2010-5-28 16:51 发表
运行前先备份原始文件:@echo off&chcp 437 >nul&Graftabl 936 >nul
(for /F "tokens=1-5* delims=," %%a in ('type "1.txt"^|more') do (
set "a=%%a,%%b,%%c,%%d,"&set "e=%%e"&set "f=,,,,,%%f"
setlocal enab ...
貌似有点小问题,发现有的表格后面的逗号有数据
1,"frame_0001.png",1,"gif","13",,,,,"000000",1,1,0,0,0,240,240,,6,0,"",0,,,,
2,"frame_0002.png",1,"gif","32","01","C",1.0,1,"000000",2,1,1,0,0,1446,1446,,6,0,"",0,,,,
2,"frame_0002.png",1,"gif","32","01","C",1.0,1,"000000",2,2,5,0,673,1446,1446,,6,0,"",0,,,,
3,"frame_0003.png",1,"gif","11",,,,,"000000",2,1,3,369,0,763,763,,6,0,"",0,,,,
3,"frame_0003.png",1,"gif","11",,,,,"000000",2,2,7,0,0,763,763,,6,0,"",0,,,,
4,"frame_0004.png",1,"gif","11",,,,,"000000",2,1,3,93,-49,531,531,,6,0,"",0,,,,
这样改了后的好像就不对了
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |