| 
 | 
 本帖最后由 tools241 于 2018-1-7 21:43 编辑  
 
利用仿Linux命令 "grep, sed, expr" 写一批处理内容如下: 
grep.exe  -n  "bbs.wuyou.net" Input.txt  |  sed.exe  -e  "s/\([0-9][0-9]*\):.*/expr.exe \1 - 2/" > output.bat 
CALL  output.bat > tmp.txt 
for  /f  %%f  in  (tmp.txt)  do  sed.exe -e "1,%%fd" Input.txt | sed.exe -e "2,$d" > output.txt 
 
_____________________________________________________________ 
 
说明: 
假设 "bbs.wuyou.net" 在 Input.txt 的第10行, 
grep.exe  -n  "bbs.wuyou.net" Input.txt 
会在搜到的行前 "加行号:" 产生 
10:bbs.wuyou.net 
 
sed.exe  -e  "s/\([0-9][0-9]*\):.*/expr.exe \1 - 2/" > output.bat 
.表示任意字, *表示前一个字出现任意次, [0-9]表示数字, 会将 \( 至  \)  内的数字存到 \1 
因此 output.bat 的内容为 
expr.exe 10 - 2 
CALL output.bat 存到 tmp.txt 的内容为  
8 
for  /f  %%f  in  (tmp.txt)  do  sed.exe -e "1,%%fd" Input.txt  
会将 Input.txt 的第1至8行删除 
sed.exe -e "2,$d" > output.txt 
再将剩余的第2行至最后一行删除. 
 
最后 output.txt 为 Input.txt 中第9行的内容. 
 
如何利用 仿Unix/Linux命令 sed 一次替换文字中的 "某/些相似性的字串"  ==> 
http://bbs.wuyou.net/forum.php?mod=viewthread&tid=383106 |   
 
 
 
 |