使用批处理将文本添加到文本文件中的特定行 [英] Add Text To A Certain Line In A Text File With Batch

查看:75
本文介绍了使用批处理将文本添加到文本文件中的特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在批处理文件中使用命令以将其追加到文本文件并在txt文件中的特定行上添加文本?​​

Is it possible to have a command used in a batch file to append to a text file and add text on a certain Line in the txt file?

Txt文件:
1
2
3
5

Txt File:
1
2
3
5

是否可以添加新行并将4置于3到5之间?

Is it possible to add a new line and put 4 between 3 and 5?

推荐答案

此答案将在 3 5 之间添加 4 .

This answer will add a 4 between a 3 and a 5.

@echo off
setlocal enabledelayedexpansion
ren in.txt in.tmp
set p=
for /f %%a in (in.tmp) do (
  if "%%a"=="5" if "!p!"=="3" Echo 4 >> in.txt
  Echo %%a >>in.txt
  set p=%%a
)
del in.tmp

这篇关于使用批处理将文本添加到文本文件中的特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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