若源文件 1.txt 是utf-8编码,须用下式且不必切换65001码页,其结果文件 2.txt 仍是utf-8编码...复制代码
- sed -E -e "s/(码:[0-9a-z]+)/\1\n/gi" -e "s/ ([0-9]{4} )/\1/g" 1.txt>2.txt
复制代码
- sed --locale=zh_cn.utf8 -E -e "s/(码:[0-9a-z]+)/\1\n/gi" -e "s/ ([0-9]{4} )/\1/g" 1.txt>2.txt
对于文本编码为ANSI复制代码
- sed -i -r "s/細(....) /細\1\n/g" 1.txt
复制代码
- sed -i -r "s/:(....) /:\1\n/g" 1.txt
若源文件 1.txt 是utf-8编码,以上代码第一行须改为如下行,且脚本代码亦须改存为utf-8编码...复制代码
- @echo off &setlocal
- (for /f "delims=" %%s in (1.txt) do set "b=%%s" &call :xxx)>2.txt
- endlocal&pause&exit/b
- :xxx
- for /f "tokens=1* delims=:" %%a in ("%b%") do (set "a=%%a"&set "b=%%b")
- if "%a:~-1%"=="码" (set/p="%a%:%b:~,4%"<nul&echo,&set "b=%b:~5%") else (set/p="%a%:"<nul)
- if "%b%"=="" (exit/b) else goto :xxx
复制代码
- @echo off &chcp 65001>nul &setlocal
欢迎光临 批处理之家 (http://bbs.bathome.net/) | Powered by Discuz! 7.2 |