【问题标题】:How to find and erase lines inside a text file如何查找和删除文本文件中的行
【发布时间】:2023-02-02 01:48:31
【问题描述】:

我有两个文本文件:

删除.txt:

red
green
blue

颜色.txt:

yellow
red
black
green
grey
blue

我想删除 collors.txt 中出现的 remove.txt 行并将其保存为 output.txt。我尝试在循环中使用 sed 命令,但无法使其工作。

脚本:

remove='remove.txt' 输入='colors.txt' 读行时;做

我没有在这里使用 sed 来完成这项工作

完成 < $删除

【问题讨论】:

  • findstr /x /v /g:"remove.txt" "collors.txt"&gt;newfile.txt 应该这样做。请参阅findstr /?,从许多关于 SO 的示例的提示中获取文档。

标签: batch-file sed command-line text-files string-comparison


【解决方案1】:

无需使用 Unix 工具,cmd 可以自己完成:

findstr /v /g:remove.txt collors.txt

查看 findstr /? 的输出以了解 /v/g 开关

使用示例文件输出:

yellow
black
grey

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-13
    • 1970-01-01
    • 2021-06-08
    • 1970-01-01
    • 2015-12-14
    • 2023-03-09
    • 1970-01-01
    相关资源
    最近更新 更多