Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 在文本文件中的固定位置插入字符串_Windows_Batch File_Text_Insert - Fatal编程技术网

Windows 在文本文件中的固定位置插入字符串

Windows 在文本文件中的固定位置插入字符串,windows,batch-file,text,insert,Windows,Batch File,Text,Insert,我需要在文本文件中的固定位置插入4个字符串: 第一个字符串:行开头第1列的产品 第二个:%%b,第20列 第三个:%%c,第33列 第四个:不存在,第42列 我总是希望字符串写在完全相同的位置,不管其他字符串之前有多长。因此,它应该如下面的示例所示: the product ergerzgtrg 65ggrth784rjhnjgbkljn doesn't exist the product reggbrtbhtrergzthrjhlyoiul

我需要在文本文件中的固定位置插入4个字符串:

  • 第一个字符串:行开头第1列的产品
  • 第二个:%%b,第20列
  • 第三个:%%c,第33列
  • 第四个:不存在,第42列
我总是希望字符串写在完全相同的位置,不管其他字符串之前有多长。因此,它应该如下面的示例所示:

the product   ergerzgtrg                  65ggrth784rjhnjgbkljn   doesn't exist  
the product   reggbrtbhtrergzthrjhlyoiul  rtjntjrez               doesn't exist
the product   zef                         rt                      doesn't exist
这是我的密码:

FOR /F "delims=; tokens=1-7*" %%a in (mytextfile.txt) do (
    if "%%e"=="Unkown" (
        echo the product         %%b          %%c          doesn't exist>>Unkown_product.txt
    )
)
mytextfile.txt如下所示:

K5134908-Blabla_4;K5134908;Blabla_4;01-69423;Unkown;K5134908-Blabla_4-516245;K5134908-Blabla_4-516245;
K2602207-Blabla_2;K2602207;Blabla_2;01-81111;Unkown;K2602207-Blabla_2-516245;K2602207-Blabla_2-516245;
K2602006-Blabla_3;K2602006;Blabla_3;01-82789;Unkown;K2602006-Blabla_3-516245;K2602006-Blabla_3-516245;
K2601507-Blabla_4;K2601507;Blabla_4;01-75135;Unkown;K2601507-Blabla_4-516245;K2601507-Blabla_4-516245;

在批处理文件(.bat)中有什么方法可以做到这一点吗?

在值中添加足够的空格(在我的示例中为20),然后剪切第一个[需要什么]字符(在我的示例中为15):


注意:根据您的文件示例,搜索字符串是
“Unknown”
(可能是打字错误,我想应该是
“Unknown”

您的示例输入和输出文件以及提供的脚本与您需要帮助的任务不匹配。你能重新考虑一下你的问题吗?它工作得很好,这就是我想要的。是的,“未知”是一个打字错误
@echo off
setlocal

FOR /F "delims=; tokens=1-7*" %%a in (mytextfile.txt) do (
    if "%%e"=="Unkown" call :format "%%b" "%%c"
)
goto :eof

:format
set "b=%~1                    "
set "c=%~2                    "
set "b=%b:~0,15%"
set "c=%c:~0,15%"
echo the product %b% %c% doesn't exist>>Unkown_product.txt