[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 批处理如何隔几行插入固定内容?

求助,需要批量处理,A变成B这样的。

A.txt
1
00:00:02,299 --> 00:00:04,830
hey


2
00:00:04,830 --> 00:00:06,569
lab
实验室

3
00:00:06,569 --> 00:00:08,130
our
我们

4
00:00:08,130 --> 00:00:10,650
seek
寻求



B.txt
1
00:00:02,299 --> 00:00:04,830
{\fn微软雅黑}hey
{\fnArial}嘿

2
00:00:04,830 --> 00:00:06,569
{\fn微软雅黑}lab
{\fnArial}实验室

3
00:00:06,569 --> 00:00:08,130
{\fn微软雅黑}our
{\fnArial}我们

4
00:00:08,130 --> 00:00:10,650
{\fn微软雅黑}seek
{\fnArial}寻求

回复 5# yhcfsr


    好的,已解决了,谢谢

TOP

回复 4# surain


    一看就知道你的脚本编码不是ANSI的,自己改成ANSI。
QQ 33892006

TOP

回复 2# yhcfsr

结果是这个
   
X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦}1 )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial}1 )  else echo;1
)
)
1

X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦}00:00:02,299 --> 00:00:04,830 )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial}00:00:02,299 --> 00:00:04,830 )  else echo;00:00:02,299 --> 00:00:04,830
)
)
00:00:02,299 --> 00:00:04,830

X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦}hey )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial}hey )  else echo;hey
)
)
{\fn寰蒋闆呴粦}hey

X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦}嘿 )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial}嘿 )  else echo;嘿
)
)
{\fnArial}嘿

X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦} )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial} )  else echo;
)
)


X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦}2 )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial}2 )  else echo;2
)
)
2

X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦}00:00:04,830 --> 00:00:06,569 )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial}00:00:04,830 --> 00:00:06,569 )  else echo;00:00:04,830 --> 00:00:06,569
)
)
00:00:04,830 --> 00:00:06,569

X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦}lab )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial}lab )  else echo;lab
)
)
{\fn寰蒋闆呴粦}lab

X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦}实验室 )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial}实验室 )  else echo;实验室
)
)
{\fnArial}实验室

X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦} )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial} )  else echo;
)
)


X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦}3 )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial}3 )  else echo;3
)
)
3

X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦}00:00:06,569 --> 00:00:08,130 )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial}00:00:06,569 --> 00:00:08,130 )  else echo;00:00:06,569 --> 00:00:08,130
)
)
00:00:06,569 --> 00:00:08,130

X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦}our  )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial}our  )  else echo;our  
)
)
{\fn寰蒋闆呴粦}our

X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦}我们 )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial}我们 )  else echo;我们
)
)
{\fnArial}我们

X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦} )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial} )  else echo;
)
)


X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦}4 )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial}4 )  else echo;4
)
)
4

X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦}00:00:08,130 --> 00:00:10,650 )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial}00:00:08,130 --> 00:00:10,650 )  else echo;00:00:08,130 --> 00:00:10,650
)
)
00:00:08,130 --> 00:00:10,650

X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦}seek )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial}seek )  else echo;seek
)
)
{\fn寰蒋闆呴粦}seek

X:\DesktopX\测试>(
set /a i+=1  
set/a "n=(i-3)%5"  
if !n! == 0 (echo;{\fn寰蒋闆呴粦}寻求 )  else (
set/a "n=(i-4)%5"  
if !n! == 0 (echo;{\fnArial}寻求 )  else echo;寻求
)
)
{\fnArial}寻求

TOP

字体好像弄反了吧,中文用微软雅黑
修改内容.bat
  1. @echo off
  2. set "file1=A.txt"
  3. set "file2=B.txt"
  4. powershell -Command "$sr=[System.IO.StreamReader]::new([System.IO.FileStream]::new('%~dp0%file1%',[System.IO.FileMode]::Open,[System.IO.FileAccess]::Read),[System.Text.Encoding]::Default);$sw=[System.IO.StreamWriter]::new([System.IO.FileStream]::new('%~dp0%file2%',[System.IO.FileMode]::Create,[System.IO.FileAccess]::Write) ,[System.Text.Encoding]::Default);$n=0;while(!$sr.EndOfStream){$s=$sr.ReadLine();if($n -eq 2){$sw.WriteLine('{\fnArial}'+$s)}elseif($n -eq 3){$sw.WriteLine('{\fn微软雅黑}'+$s)}else{$sw.WriteLine($s)}if($n -eq 4){$n=0;$sw.Flush()}else{$n++}}$sw.Flush();$sr.Close();$sw.Close()"
  5. pause
  6. exit /b
复制代码

TOP

  1. @echo off&setlocal enabledelayedexpansion
  2. (for /f "tokens=1* delims=:" %%a in ('findstr /n ".*" "A.txt"') do (
  3. set /a i+=1
  4. set/a "n=(i-3)%%5"
  5. if !n!==0 (echo;{\fn微软雅黑}%%b) else (
  6. set/a "n=(i-4)%%5"
  7. if !n!==0 (echo;{\fnArial}%%b) else echo;%%b
  8. )
  9. ))>B.txt
复制代码
QQ 33892006

TOP

返回列表