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

[文本处理] 批处理怎样进行特殊符号和数字的替换?

本帖最后由 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 发表
运行前先备份原始文件:@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,,,,

这样改了后的好像就不对了

TOP

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

TOP

原始文件是什么编码格式?
哪个版本的sed?
你写的sed命令是什么?

TOP

本帖最后由 pcl_test 于 2017-6-8 20:59 编辑

运行前先备份原始文件:
  1. @echo off&chcp 437 >nul&Graftabl 936 >nul
  2. (for /F "tokens=1-5* delims=," %%a in ('type "1.txt"^|more') do (
  3. set "a=%%a,%%b,%%c,%%d,"&set "e=%%e"&set "f=,,,,,%%f"
  4. setlocal enabledelayedexpansion
  5. if !e:~1^,-1! lss 256 set e="15"
  6. echo.!a!!e!!f!
  7. Endlocal))>$
  8. move $ 1.txt
复制代码
[ 本帖最后由 hanyeguxing 于 2010-5-28 16:53 编辑 ]
寒夜孤星:在没有说明的情况下,本人所有代码均运行在 XP SP3 下 (有问题请发贴,QQ临时会话已关闭)

TOP

返回列表