标题: [文本处理] 【已解决】批处理如何在输出一行数据的末尾,加上换行符? [打印本页]
作者: 思想之翼 时间: 2014-7-26 02:45 标题: 【已解决】批处理如何在输出一行数据的末尾,加上换行符?
- @echo off
- cd /d "e:\123\文件夹1"
- (for %%i in (*.txt) do (
- setlocal enabledelayedexpansion
- for /f "delims=" %%a in (%%i) do (
- for %%b in (%%a) do (
- if not defined #%%b set #%%b=100000
- set/a #%%b+=1
- )
- )
- (for /f "tokens=2" %%z in ('^(for /f "tokens=1-2 delims=#=" %%a in ^('set #'^)do @echo,%%b %%a^)^|sort /r') do set/p=%%z )>"文件夹2\%%i"
- endlocal
- ))<nul
复制代码
若要在输出的每个文本的数据后,加一个换行符 (Entet),如何修改代码?
作者: apang 时间: 2014-7-26 13:56
小改一下:- @echo off
- cd /d "文件夹1"
- for %%i in (*.txt) do (
- setlocal enabledelayedexpansion
- for /f "usebackq delims=" %%a in ("%%i") do (
- for %%b in (%%a) do (
- if not defined #%%b (set #%%b=100001)else set/a #%%b+=1
- )
- )
- for /f "tokens=2" %%z in ('^(for /f "tokens=1-2 delims=#=" %%a in ^('set #'^)do @echo,%%b %%a^)^|sort/r')do set a=!a! %%z
- echo,!a:~1!>"..\排序1\%%i"
- endlocal
- )
复制代码
作者: apang 时间: 2014-7-26 14:03
如果文本数据全部是固定的两位数,或许可以这样:- @set @n=0;/* & echo off
- pushd "文件夹1\"
- dir /b *.txt | cscript -nologo -e:jscript "%~0"
- pause & exit/b & rem */
-
- fso = new ActiveXObject("Scripting.FileSystemObject");
- while (!WScript.StdIn.AtEndOfStream) {
- f = WScript.StdIn.ReadLine();
- txt = fso.OpenTextFile(f, 1).ReadAll();
- ar = [];
- for (i=100; i<=199; i++) {
- j = (i + "").substr(1);
- n = txt.split(j).length;
- if (n > 1) ar.push(n + 100000000 + "=" + j)
- }
- ar.sort().reverse();
- s = ar.join(" ").replace(/\d+=/g, "");
- fso.CreateTextFile("..\\排序1\\"+f, true).WriteLine(s)
- }
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |