如何从文本文件中删除一些单词?

时间:2018-02-21 09:47:05

标签: batch-file

以下是我在Windows中的批处理文件的代码。

@echo off
setlocal EnableDelayedExpansion

if exist raw_scores.csv del raw_scores.csv
for %%f in (*.txt) do (
    set i=0
    for /F "delims=" %%l in (%%f) do (
        set /A i+=1
        set line!i!=%%l
    )
    echo %%f, !line2!, !line1!, !line4! >> raw_scores.csv
)

以下是csv格式的Windows批处理文件的结果。

quiz_result_2018-02-08_05-34-20.txt  User Name: manoj    Quiz Name: Physics  User Score: 53
quiz_result_2018-02-08_06-02-05.txt  User Name: Pooja    Quiz Name: Chemistry    User Score: 61
quiz_result_2018-02-08_06-07-11.txt  User Name: Temujin  Quiz Name: Biology  User Score: 93

现在我想从csv文件的最终结果中删除一些单词。这些是"User Name:", "Quiz Name:", "User Score:"。所以,它看起来像......

quiz_result_2018-02-08_05-34-20.txt manoj   Physics 53

quiz_result_2018-02-08_06-02-05.txt Pooja   Chemistry   61

quiz_result_2018-02-08_06-07-11.txt Temujin Biology 93

1 个答案:

答案 0 :(得分:0)

echo %%f, !line2:user name:=!, !line1:quiz name:=!, !line4:score:=! >> raw_scores.csv

应该根据需要删除文本,假设这些字符串出现在行上。

但是,您的报告不包含代码指示的。请发布示例数据完全