Re: [批次] 在每行开头新增资料

楼主: VElysian (くるみ)   2016-09-14 00:09:17
※ 引述《wopicoun (挖屁康)》之铭言:
: 小弟初学batch file
: 想问下如果有我一个txt档如下
: 123 apple
: 456465 orange
: 88 banana
: .
: .
: .
: 第一栏是数字,第二栏是字串,
: 1.我想要将每一行通过第一栏排序大小
: 2.之后在开头新增一个新的字段,放其他字串例如 Aa 123 apple 这样
: 大致拆成两步,请问如何只用bat完成呢?
: 感谢
1.
有一些文字编辑器有排序功能
加字的话可以用 regular expression 搜寻取代
2.
批次档不敷使用
可改用 AutoHotKey (XD)
延虚线剪下贴上即可
尚未测试
使用前请备份档案 XD
===== 8< =====
; 将档案内容读入 content 变量
FileRead, content, C:\要处理的文字档.txt
; 排序档案
if not ErrorLevel ; 读取成功
{
; 排序
sort, content
; 写入
FileAppend, %content%, C:\要处理的文字档_已排序.txt
content = ;释放内存
}
; 开头文字
head = Aa
; 读取每行
Loop
{
; 读取
FileReadLine, line, C:\要处理的文字档_已排序.txt, %A_Index%
; 增加文字
line = %head% %line%
; 读取错误则跳出
if ErrorLevel
break
; 写入此行
FileAppend, %line%, C:\要处理的文字档_已加字.txt
}
===== >8 =====
参考资料
https://www.autohotkey.com/docs/Tutorial.htm
https://www.autohotkey.com/docs/commands/Sort.htm
https://www.autohotkey.com/docs/commands/FileAppend.htm
https://www.autohotkey.com/docs/commands/FileReadLine.htm
作者: fossil313 (阵雨)   2016-09-14 02:01:00
是版主!
作者: wopicoun (挖屁康)   2016-09-14 07:42:00
感谢版主,我原本是希望只用bat做,看来是不行了

Links booklink

Contact Us: admin [ a t ] ucptt.com