使用批处理文件查找/替换文件中的文本

时间:2021-11-15 16:50:29

i need to replace a portion of a line of text with another line of text ex:

我需要用另一行文本替换一行文本的一部分ex:

07/24/2012 06:30:00    <--what i start with
07/24/2012 06:30:00 Name=weather  <---is what i need it to look like

every day the date changes and i have about 20 of these lines to change every day, whats the easiest way to do this using a bat file, i want to be able to run it and it would open the file, change what needed to be changed then spit out the changed text file in another location. there are hundreds of lines in this text file that need to stay in the new one and not change only about 20 or so need to be changed. i dont need it to loop at all since every time i need to edit the file the text needed to change will be exactly the same and it will need to change the same number of lines each time. thanks in advance

每天日期都会改变,我每天都会有大约20条线路改变,最简单的方法是使用bat文件,我想能够运行它,它会打开文件,改变需要的东西更改然后在另一个位置吐出更改的文本文件。此文本文件中有数百行需要保留在新文本中,而且只需更改大约20行左右需要更改。我根本不需要它循环,因为每次我需要编辑文件时,需要更改的文本将完全相同,并且每次都需要更改相同的行数。提前致谢

1 个解决方案

#1


1  

One way using sed:

使用sed的一种方法:

sed -e "s/\(.*\)/\1 Name=weather/" file.txt > /your/new/location/newfile.txt

Perhaps you should update your question, to include example input and expected output. But the above line should get you started.

也许您应该更新您的问题,包括示例输入和预期输出。但是上面这行应该让你开始。

#1


1  

One way using sed:

使用sed的一种方法:

sed -e "s/\(.*\)/\1 Name=weather/" file.txt > /your/new/location/newfile.txt

Perhaps you should update your question, to include example input and expected output. But the above line should get you started.

也许您应该更新您的问题,包括示例输入和预期输出。但是上面这行应该让你开始。