查找字符串并替换批处理文件中的特定字母 [英] Find a string and replace specific letters in batch file

查看:31
本文介绍了查找字符串并替换批处理文件中的特定字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个 autosys 作业来触发一个批处理文件,该文件会找到一个特定的字符串,然后替换接下来的 4 个字符.

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.

我应该用INFA"替换socc"

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.

谢谢,喜悦

推荐答案

@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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆