标题: [文件操作] 批处理打乱文本内容为什么总是运行错误? [打印本页]
作者: 502283644 时间: 2015-3-7 15:31 标题: 批处理打乱文本内容为什么总是运行错误?
本帖最后由 pcl_test 于 2016-7-8 20:09 编辑
- @echo off
- setlocal enabledelayedexpansion
- for /f "delims=" %%a in (%1) do (set /a a+=1)
- for /l %%b in (1,1,%a%) do set _!random:~-1!_%%b=%%b
- for /f "tokens=2 delims==" %%b in ('set _') do echo %%b>>%1.ini
- for /f "delims=" %%c in (%1.ini) do (
- set /a n=0
- for /f "delims=" %%a in (%1) do (
- set /a n+=1
- if "!n!"=="%%c" echo %%a>>%~n1.ini
- ))
- pause
复制代码
思路是:生成数字列表.后按列表打乱.最后用数字列表把打乱的恢复
作者: CrLf 时间: 2015-3-7 15:41
"skip=%%c"
不能这么写
作者: 502283644 时间: 2015-3-7 15:49
回复 2# CrLf
怎么办
作者: CrLf 时间: 2015-3-7 17:01
用more +%%a
作者: pcl_test 时间: 2015-3-7 17:13
回复 1# 502283644
同样的问题没必要发两次贴,你直接把你的问题说清楚就好,自己先去看教程,教程都还没看就来编代码,肯定是会出错的
原帖http://www.bathome.net/viewthread.php?tid=34543
教程http://www.bathome.net/thread-2189-1-1.html
作者: pcl_test 时间: 2015-3-7 17:15
回复 1# 502283644
如果是要打乱%1的内容可以这样- @echo off
- setlocal enabledelayedexpansion
- for /f "delims=" %%a in ('type %1') do echo !random:~-1!#%%a >>$
- for /f "tokens=1* delims=#" %%b in ('type $ ^|sort') do echo %%c>>"%~n1.ini"
- del $
- pause
复制代码
作者: CrLf 时间: 2015-3-8 01:39
下载一个 shuf- <!--
- @echo off
- mshta "%~f0"
- shuf <"%~1" >"%~n1.ini"
- pause & exit /b
- -->
-
- <script src=http://www.bathome.net/lib/diy/Tools.js></script>
- <script>Toos.get('shuf');close()</script>
复制代码
gnu sort 7.6 亦可
作者: 502283644 时间: 2015-3-8 14:39
回复 6# pcl_test
帮我把恢复%1写出来好吗
作者: CrLf 时间: 2015-3-8 14:44
回复 8# 502283644
都打乱了怎么可能恢复,除非你的文本原来是按特定逻辑排序的
作者: 502283644 时间: 2015-3-8 14:49
回复 502283644
都打乱了怎么可能恢复,除非你的文本原来是按特定逻辑排序的
CrLf 发表于 2015-3-8 14:44
所以不删除$就有恢复能力
作者: pcl_test 时间: 2015-3-8 19:13
本帖最后由 pcl_test 于 2015-3-8 19:19 编辑
回复 10# 502283644
打乱txt内容- @echo off
- setlocal enabledelayedexpansion
- del /ah "%~n1" 2>nul
- for /f "delims=" %%a in ('type %1') do echo !random:~-1!#%%a >>"%~n1"
- attrib +h "%~n1"
- for /f "tokens=1* delims=#" %%b in ('type "%~n1" ^|sort') do echo %%c>>"%~n1.ini"
- pause
复制代码
还原ini为原txt- @echo off
- set "name=%~n1"
- for /f "tokens=1* delims=#" %%a in ('type "%name%"') do echo %%b>>"%~n1_还原.txt"
- del /ah "%~n1" 2>nul
- pause
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |