在文本文件的特定位置添加字符串

Adding strings at certain places in a text file

我有一个包含以下内容的文本文件:

-849.4471 1272.173 22.8698 0 0 -1 7.54979E-008 Fire_Esc_6 385 792 24 -1
-837.0507 1270.862 28.1249 0 0 -1 7.54979E-008 Fire_Esc_6b 385 792 24 -1
-837.0654 1270.879 24.09248 0 0 -1 7.54979E-008 Fire_Esc_6 385 792 24 -1

对于每一行,我需要

我是批处理的初学者,不知道从哪里开始。不胜感激。

我在 somethingDark 的帮助下完成了这里 :0

FOR /F "tokens=8* delims= " %%G IN (C:\Users\Sherlock\DocumentsDReaperDX\Frames.txt) DO ECHO set %%G >12.txt

既然你已经尝试自己解决这个问题,我更愿意向你展示我对你的脚本的设想。

@echo off

:: If 12.txt exists, delete it. This way, the entire file will be recreated when the script is re-run.
:: (If you don't want this to happen and you just want new data added to the end of the file every
::  time the script is run, just delete this part.)
if exist 12.txt del 12.txt


:: An example line looks like this:
:: -849.4471 1272.173 22.8698 0 0 -1 7.54979E-008 Fire_Esc_6 385 792 24 -1

:: Iterate through each line in 1.txt, storing each space-delimited string in a unique variable
:: %%A: -849.4471
:: %%B: 1272.173
:: %%C: 22.8698
:: %%D: 0
:: %%E: 0
:: %%F: -1
:: %%G: 7.54979E-008
:: %%H: Fire_Esc_6
:: Since we don't care about anything after the eighth token, we can just ignore it
:: The redirection command is at the start of the line to avoid an extra space at the end of the line
for /f "tokens=1-8" %%A in (C:\Users\Sherlock\DocumentsDReaperDX\Frames.txt) do >>12.txt echo setAttr "sth"; %%A sth %%B %%C %%D %%E %%F %%G %%H

因为这个脚本太短了(它实际上只有三行和一大堆注释),你甚至可以从命令行 运行 这个一行:

for /f "tokens=1-8" %A in (C:\Users\Sherlock\DocumentsDReaperDX\Frames.txt) do >>12.txt echo setAttr "sth"; %A sth %B %C %D %E %F %G %H

这将创建包含以下内容的文件 12.txt

setAttr "sth"; -849.4471 sth 1272.173 22.8698 0 0 -1 7.54979E-008 Fire_Esc_6
setAttr "sth"; -837.0507 sth 1270.862 28.1249 0 0 -1 7.54979E-008 Fire_Esc_6b
setAttr "sth"; -837.0654 sth 1270.879 24.09248 0 0 -1 7.54979E-008 Fire_Esc_6