本帖最后由 pcl_test 于 2015-2-9 16:59 编辑
回复 1# heychaw
假设有文档test.txt- @echo off
- setlocal enabledelayedexpansion
- set n=0
- set m=1
- for /f "delims=" %%a in ('type "test.txt"') do (
- set /a n+=1
- )
-
- :getnumber
- set /a t1=2+%random%%%(2-n+1)
- set /a t2=2+%random%%%(2-n+1)
- set /a t3=2+%random%%%(2-n+1)
-
- if %t1%==%t2% (
- goto getnumber
- ) else (
- if %t2%==%t3% (
- goto getnumber
- ) else (
- if %t1%==%t3% (
- goto getnumber
- ) else (
- goto getecho
- )
- )
- )
-
- :getecho
- echo 代码将随机添加到第%t1%、%t2%、%t3%行
- for /f "delims=" %%a in ('type "test.txt"') do (
- if !m!==1 (
- set str=%%a
- set str=!str:~3,-4!
- >"tmp.txt" echo,!str!
- ) else (
- if !m!==%t1% (
- >>"tmp.txt" echo,%%a{-File.GetString-^|-D:\article\aaaa-^|-0-^|-false-}
- ) else (
- if !m!==%t2% (
- >>"tmp.txt" echo,%%a{-File.GetString-^|-D:\article\aaaa-^|-0-^|-false-}
- ) else (
- if !m!==%t3% (
- >>"tmp.txt" echo,%%a{-File.GetString-^|-D:\article\aaaa-^|-0-^|-false-}
- ) else (
- >>"tmp.txt" echo,%%a
- )
- )
- )
- )
- set /a m+=1
- )
-
- rem move "tmp.txt" "test.txt"
- echo 完成!
- pause
复制代码
|