标题: [文本处理] [已解决]批处理如何将txt文本按每行行尾的数字大小排序? [打印本页]
作者: zwgxsy 时间: 2011-8-10 09:27 标题: [已解决]批处理如何将txt文本按每行行尾的数字大小排序?
本帖最后由 pcl_test 于 2016-7-12 17:00 编辑
比如:
http://www.baidu.com/ 排名:6
http://www.google.com/ 排名:1
http://www.bathome.net/ 排名:340977
结果:
http://www.google.com/ 排名:1
http://www.baidu.com/ 排名:6
http://www.bathome.net/ 排名:340977
求解
作者: CrLf 时间: 2011-8-10 10:35
- @echo off&setlocal enabledelayedexpansion
- %1 for /f "tokens=1* delims=:" %%a in ('%0 ::^|sort') do echo %%b
- %1 pause&exit
- for /f "tokens=1* delims=:" %%a in (1.txt) do (
- set n= %%b
- echo !n:~-6!:%%a:%%b
- )
复制代码
作者: ArdentMan 时间: 2011-8-10 10:49
赞!
用::来做参数起到第二次注释二三句的作用
参数真是
用神了
神了
神
作者: zwgxsy 时间: 2011-8-10 16:53
@echo off&setlocal enabledelayedexpansion
%1 for /f "tokens=1* delims=:" %%a in ('%0 ::^|sort') do echo %%b
%1 pause&exit
for /f "tokens=1* delims=:" %%a in (11.txt) do (
set n= %%b
echo !n:~-6!:%%a:%%b >>2.txt
)
结果怎么是
1:http://www.google.com/ 排名:1
340977:http://www.bathome.net/ 排名:340977
6:http://www.baidu.com/ 排名:6
作者: CrLf 时间: 2011-8-10 16:57
输出最终结果的是第一个 for,而不是第二个 for
作者: zwgxsy 时间: 2011-8-10 17:01
确实有点晕了,不过问题解决了,谢谢。
作者: pcl_test 时间: 2016-7-12 17:08
- //&cls&dir /a-d/b 1.txt|cscript -nologo -e:jscript "%~f0"&pause&exit
-
- var fso = new ActiveXObject('Scripting.Filesystemobject');
- function SortNumber(file){
- var f = fso.OpenTextFile(file, 1);
- try{
- var txt = f.ReadAll().split(/\r\n/).sort(
- function(a, b){return Number(a.replace(/.*(\d+)\s*$/, '$1'))-Number(b.replace(/.*(\d+)\s*$/, '$1'))}
- ).join('\r\n');
- f.Close();
- fso.OpenTextFile(file, 2).Write(txt);
- }catch(e){}
- }
- while(!WSH.StdIn.AtEndOfStream)SortNumber(WSH.StdIn.ReadLine());
- WSH.echo('Done');
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |