【问题标题】:Delete certain lines in a txt file via a batch file based on column position value match根据列位置值匹配通过批处理文件删除txt文件中的某些行
【发布时间】:2016-02-20 04:06:06
【问题描述】:

我有一个包含固定长度数据的文本文件。

1234|test1|2015|Who are you
4567|test2||I'm a dumb guy
1234|test1|2015|We all know

我只需要通过检查第 12 位值是否为 2 来删除第 2 行(当前年份,因此在 2099 年之前的所有行都将始终为 2 :))然后删除该行。换句话说,只需获取位置 12 中包含值 2 的行。

我尝试搜索并找到了这个,但我不知道如何重写以查找位置 = 值。

输入文件.txt | findstr /v 错误 | findstr /v 引用

Delete certain lines in a txt file via a batch file

非常感谢..

【问题讨论】:

    标签: windows batch-file command-line delete-row


    【解决方案1】:
    findstr /r "...........2" "Data.txt"
    

    请参阅findstr /? 寻求帮助。还有help。

    将输出重定向到文件。

    findstr /r "...........2" "c:\folder\Data.txt" > "c:\folder\Output.txt"
    

    请参阅Trouble with renaming folders and sub folders using Batch 获取标点帮助。

    【讨论】:

    • 不会是/v /r吗?
    • 他要保留2nnn而不是失去2nnn。这个更好^...........2[0-9][0-9][0-9]
    猜你喜欢
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2022-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多