查找字符串并替换批处理文件中的具体信件 [英] Find a string and replace specific letters in batch file
本文介绍了查找字符串并替换批处理文件中的具体信件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个创建一个autosys任务触发一个批处理文件,它会找到一个特定的字符串,然后替换下一个4个字符。
例如,如果文件(多线)具有如下内容和我正在寻找发挥
疯狂的狐狸跳老藤和
踢足球。
我要替换SOCC与INFA
我是新来的批处理文件和我的带动下一直坚持到我这样做只是使用批处理文件。任何帮助将大大apprciated。
谢谢,
欢乐
解决方案
关闭@echo和放大器; SETLOCAL
设置=搜索字符串
设置替换= kordo anstataui
设置文本文件file.txt的=
集的newfile = new.txt(FOR / Fdelims =%% i的('FINDSTR / N^%文本文件%')做(
一套行= %%我
SETLOCAL enabledelayedexpansion
一套行=行:%搜索%=%替换%!
回声(!行!
ENDLOCAL
))>中%的newfile%
键入%的newfile%
I have a to create an autosys job to trigger a batch file which would find a specific string and then replace the next 4 characters.
For example if file (with multiple lines) has below content and i am searching for played
the mad fox jumped of the old vine and played soccer.
I should replace "socc" with "INFA"
I am new to batch files and my lead has been insisting that i do this using a batch file only. Any help would be greatly apprciated.
Thanks, Joy
解决方案
@echo off &setlocal
set "search=search string"
set "replace=kordo anstataui"
set "textfile=file.txt"
set "newfile=new.txt"
(for /f "delims=" %%i in ('findstr /n "^" "%textfile%"') do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:%search%=%replace%!"
echo(!line!
endlocal
))>"%newfile%"
type "%newfile%"
这篇关于查找字符串并替换批处理文件中的具体信件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文