批处理文件删除从txt文件第18个字符 [英] Batch file to remove first 18 chars from txt file
本文介绍了批处理文件删除从txt文件第18个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有超过32000行注释掉机code的一个.txt文件。它看起来是这样的:
I have a .txt document with over 32,000 lines of commented machine code. It looks like this:
Display menu window
C0/000E: E220 SEP #$20
C0/0010: C210 REP #$10
C0/0012: 20640B JSR $0B64
C0/0015: 20750B JSR $0B75
C0/0018: C220 REP #$20
C0/001A: A90001 LDA #$0100
我需要转换code编译用途如下:
I need to convert the code as follows for compiling purposes:
; Display menu window
SEP #$20
REP #$10
JSR $0B64
JSR $0B75
REP #$20
LDA #$0100
具体而言,这意味着:
Specifically, that means:
- 空白行必须保持不变。
- 如果一个行以C0 /,那么前18个字符将被删除,包括标签。
- 否则,它是一个函数题,所以一开始(非强制)添加一个分号后面加一个空格。
任何帮助将大大AP preciated。
Any help would be greatly appreciated.
推荐答案
下面的批处理文件是可能比其他类似的方法快了不同的方法,但是这很大程度上取决于文件的大小:
The Batch file below is a different approach that may run faster than other similar methods, but this largely depends on the size of the file:
@echo off
for /F "tokens=1-2*" %%a in ('findstr /N "^" test.txt') do (
for /F "tokens=1,2 delims=:/" %%d in ("%%a") do (
if "%%e" equ "C3" (
echo %%c
) else if "%%e" neq "" (
echo ; %%e %%b %%c
) else (
echo/
)
)
)
然而,最快的方法是通过一个批次的JScript脚本混合。与.bat扩展名保存以下文件:
However, the fastest method is via a Batch-JScript hybrid script. Save the file below with .bat extension:
@set @Batch=1 /*
@cscript //nologo //E:JScript "%~F0" < test.txt
@goto :EOF & rem */
WScript.Stdout.Write(WScript.Stdin.ReadAll().replace
(/^C3\/.{15}|^(..)/gm,function(A){return A.length==2?"; "+A:""}));
这篇关于批处理文件删除从txt文件第18个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文