gpt4 book ai didi

batch-file - 使用批处理文件查找和替换文本

转载 作者:行者123 更新时间:2023-12-03 13:00:15 26 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





How can you find and replace text in a file using the Windows command-line environment?

(30 个回答)


8年前关闭。




我需要一个批处理文件,它在文本文件中搜索字符串并将其替换为另一个字符串。我试着做类似 this 的事情但它不起作用。谁能告诉我我做错了什么?

@echo off
setLocal DisableDelayedExpansion

if not exist "%1" (echo FindAndReplace: File Not Found)
set /p findX= Find ?
set /p replaceWithX= Replace With ?

for /f "tokens=* delims= " %%G in (%1) do (
set str=%%G
setLocal EnableDelayedExpansion
set str=!str:[%findX%]=[%replaceWithX%]!
>> %1.txt echo(!str!
endlocal
)

最佳答案

一些有助于查找命令的代码是它的帮助菜单

在一个或多个文件中搜索文本字符串。

FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]

/V Displays all lines NOT containing the specified string.
/C Displays only the count of lines containing the string.
/N Displays line numbers with the displayed lines.
/I Ignores the case of characters when searching for the string.
/OFF[LINE] Do not skip files with offline attribute set.
"string" Specifies the text string to find.
[drive:][path]filename
Specifies a file or files to search.

If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.

关于batch-file - 使用批处理文件查找和替换文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6981608/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com