0

我想创建一个批处理文件,该文件通过目录中的 txt 文件和其中包含 #EXTINF 的每一行,删除最后 15 个字符..

基本上,如果可能的话,我想从任何长于某个数字的行中修剪最后 15-20 个字符。出于某种原因,我有一个软件,如果线路太长,它会搞砸数据。

谢谢

4

2 回答 2

0

对于一个文件:

@Echo OFF

(For /F "Usebackq Tokens=*" %%# in ("MyFile.txt") Do (
    Echo "%%#" | FIND /I "#EXTINF" 1>NUL && (
        Set "Line=%%#"
        Call Set "Line=%%Line:~0,-1%%"
        Call Echo %%Line%%
    ) || (
        Echo %%#
    )
))>"MyNewFile.txt"

Pause&Exit

对于所有文件:

@Echo OFF

For %%@ in (*.txt) DO (

    (For /F "Usebackq Tokens=*" %%# in ("%%@") Do (

        Echo "%%#" | FIND /I "#EXTINF" 1>NUL && (
            Set "Line=%%#"
            Call Set "Line=%%Line:~0,-1%%"
            Call Echo %%Line%%
        ) || (
            Echo %%#
        )

    ))>"%%@_New.txt"
)

Pause&Exit
于 2013-04-24T07:14:01.703 回答
0

GnuSed 是比批处理更好的文本编辑工具。这是针对单个文件

@echo off
sed "s/^\(.*#EXTINF.*\).$/\1/" "filein.txt" >"fileout.txt"

对于多个文件(将从 fileone.txt 生成 fileone.new.txt)

@echo off
for /f "delims=" %%a in ('dir *.txt /b') do sed "s/^\(.*#EXTINF.*\).$/\1/" "%%a" >"%%~na.new%%~xa"
于 2013-04-24T07:38:18.510 回答