使用 DOS 批处理文件从文件中删除某些内容

2024-03-25

我有一个文件“Text.dat”,其中包含一些不需要的数据。我需要编写一个 DOS 批处理文件来删除不需要的数据,并将其放入其他文件(例如“file2.dat”)中,并保留包含所需数据的原始文件。请帮忙


代替find我会用findstr哪个更强大find.

要创建仅包含不需要的数据的文件:

findstr "unwanted" text.dat > unwanted.dat

要从 text.dat 创建一个新文件并删除“不需要的”数据:

findstr /v "unwanted" text.dat > text_cleaned.dat

Online findstr可以找到参考here http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/findstr.mspx?mfr=true.

完整命令行参考:

C:\>findstr /?
Searches for strings in files.

FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file]
        [/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]]
        strings [[drive:][path]filename[ ...]]

  /B         Matches pattern if at the beginning of a line.
  /E         Matches pattern if at the end of a line.
  /L         Uses search strings literally.
  /R         Uses search strings as regular expressions.
  /S         Searches for matching files in the current directory and all
             subdirectories.
  /I         Specifies that the search is not to be case-sensitive.
  /X         Prints lines that match exactly.
  /V         Prints only lines that do not contain a match.
  /N         Prints the line number before each line that matches.
  /M         Prints only the filename if a file contains a match.
  /O         Prints character offset before each matching line.
  /P         Skip files with non-printable characters.
  /OFF[LINE] Do not skip files with offline attribute set.
  /A:attr    Specifies color attribute with two hex digits. See "color /?"
  /F:file    Reads file list from the specified file(/ stands for console).
  /C:string  Uses specified string as a literal search string.
  /G:file    Gets search strings from the specified file(/ stands for console).
  /D:dir     Search a semicolon delimited list of directories
  strings    Text to be searched for.
  [drive:][path]filename
             Specifies a file or files to search.

Use spaces to separate multiple search strings unless the argument is prefixed
with /C.  For example, 'FINDSTR "hello there" x.y' searches for "hello" or
"there" in file x.y.  'FINDSTR /C:"hello there" x.y' searches for
"hello there" in file x.y.

Regular expression quick reference:
  .        Wildcard: any character
  *        Repeat: zero or more occurances of previous character or class
  ^        Line position: beginning of line
  $        Line position: end of line
  [class]  Character class: any one character in set
  [^class] Inverse class: any one character not in set
  [x-y]    Range: any characters within the specified range
  \x       Escape: literal use of metacharacter x
  \<xyz    Word position: beginning of word
  xyz\>    Word position: end of word
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 DOS 批处理文件从文件中删除某些内容 的相关文章

  • “FOR”在cmd批处理文件中如何工作?

    20 年来我一直在使用数十种语言进行编程 但无论我如何努力 我始终无法理解 Windows cmd shell 批处理文件中的 FOR 是如何工作的 我读 http www ss64 com nt for html http www ss6
  • 什么可能导致 PUSHD 失败?

    我有一个很棒的大脚本 完全依赖于 PUSHD 然而当我打字时突然pushd server1 dir1我越来越 C Documents and Settings userNameHere gt pushd server1 dir1 CMD d
  • powershell批处理管道

    以下行在 powershell 2 0 中运行良好 servermanagercmd exe query Select String Application Server Context 0 13 但是当我将它合并到我的批处理文件中时 它只
  • 没有权限从任务计划程序写入文件?

    我得到了一个批处理文件 它将运行 C 程序并输出到带有 gt 重定向的文件 该文件将由任务调度程序运行 我发现当从任务计划程序运行批处理文件时 它声称 访问被拒绝 批处理文件运行良好 直到到达 gt 重定向部分 我看到整个批次可以在没有 g
  • 在 Windows 系统上移动文件的最快方法 [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我想要将大约 800GB 的数据从 NTFS 存储设备移动到 FAT32 设备 两者都是外部硬盘驱动器 在 Windows 系统上 实现这
  • 用于在命令提示符下运行 .exe 的 Bat 文件

    我想创建一个 bat 文件 这样我只需单击它即可运行 svcutil exe language cs out generatedProxy cs config app config http localhost 8000 ServiceMo
  • Windows 在 PATH 中搜索可执行文件的相对顺序是什么?

    如果我有a com a cmd a bat and a exe我的文件中的 PATH 如果我只调用该命令 Windows 会选择哪一个a 这是微软官方指定的吗 我只是想包裹我的gvim exe可执行文件 n 但是我的gvim bat似乎既不
  • 使用批处理文件自动化 Windows 命令行实用程序 - 在实用程序启动后将击键发送到 std 输入

    我有一个命令行实用程序 它打开由命令行中发送的参数指定的串行连接 该实用程序启动后 我可以在 std 输入中键入内容 以将字符串发送到我所连接的端口 我想做的是使用批处理文件启动该实用程序 足够简单 然后自动执行我希望发送的击键 我自己运气
  • 如何使用批处理全屏打开窗口

    我之前用代码制作了一个批处理文件 start chrome exe profile directory Profile 1 http drive google com 它会以配置文件 1 用户的身份打开 google chrome 页面 D
  • 如何删除所有超过 2 天的空文件夹?

    我制作了一个脚本 删除路径中带有子文件夹的所有空文件夹 现在我必须做的是 如果一个文件夹是 2 天前创建的 并且它是空的 则应该将其与其他早于 2 天的空文件夹一起删除 如果不是 则不应删除它 我还需要 想要将已删除的文件夹写入日志中 我用
  • 使用单个字符串查找多个文件路径

    我尝试编写一个批处理脚本来查找与输入字符串同名的文件的所有路径 现在它只能找到找到的第一个文件 我想不出一种方法让它列出多个文件位置 我经验不足 需要一些帮助 这是脚本代码的一部分 start cls echo Enter file nam
  • 从 ANT 运行 BAT 文件

    我浏览了论坛上的许多帖子 但无法整理出来 我正在尝试从 ANT 脚本运行 BAT 文件 文件夹层次结构是这样的 Project build xml build C test bat 我编写的 ANT 文件是
  • 批处理文件随机删除文本文件的一半行?

    我需要一种方法来使用批处理来查看文本文件的每一行 并删除该文本文件中的一半行 随机选择要删除的行 这是为了模拟 D D 游戏中的锦标赛 我所需要的只是一种方法来淘汰每轮比赛的获胜者 我可以轻松地制作一个批处理文件 复制文本文件并为每一轮重命
  • 每次批量从选择中获取随机句子

    有没有一种方法可以做到这一点 而不是每次都设置相同的回显 您可以给出一个回显列表 并且每次到达该回显命令时它都会选择一个随机的回显 是的 这是一个概念证明 echo off setlocal enabledelayedexpansion s
  • 阻止 gulp 更改 shell/cmd 标题名称

    当 gulp 被调用时 它会将我的 cmd windows 标题更改为 gulp 我希望窗口名称保持原样 我知道我可以使用https www npmjs com package gulp shell https www npmjs com
  • bat 文件修改 web.config 设置

    我在 Visual Studio 2013 中创建了一个 Web 应用程序 我的 Web Config 文件中有此 appSetting
  • 以管理员身份从 cmd 批处理运行 PowerShell 脚本

    我有一个 PowerShell 设置 我想在执行策略可能受到限制并且需要管理员权限的计算机上执行 理想情况下 我可以将其包装在 cmd 批处理中 如下所示 powershell Command Start Process powershel
  • 使用javascript批量上传请求到Google Cloud Storage

    我正在尝试使用 javascript 在批量请求中将多个图像上传到谷歌云存储 我在用着https developers google com storage docs json api v1 how tos batch example ht
  • 批量设置变量=%变量:~1%是什么意思

    谁能解释一下是什么 1 在批处理文件中的以下语句中 我分配的值 variable到服务器名称并尝试过echo variable 我得到与输出相同的服务器名称 谁能解释一下下面的语句是如何工作的 set variable variable 1
  • 如何在批处理文件中测试当前驱动器号?

    我正在尝试编写一个批处理文件 该文件获取运行批处理文件的驱动器号 并使用它的 IF 语句 例如如果字母是M 则会跳转到标签 mSection 这可能吗 您可以使用 d0 来获取驱动器号 像这样的东西 IF d0 M CALL mSectio

随机推荐