[英]I need to update one line in multiple files which are in different folders and all united in one folder
I need to update(Delete one line and add one more line in the same place) one line in multiple files which are in different folders and all united in one folder.My folder structure is as below我需要更新(删除一行并在同一位置再添加一行)在不同文件夹中的多个文件中的一行,并且所有文件都在一个文件夹中。我的文件夹结构如下
Scripts脚本
Component1 (Many components) moduleName1 moduleScript1.groovy moduleName2 moduleScript2.groovy (Many modules) Component1 (Many components) moduleName1 moduleScript1.groovy moduleName2 moduleScript2.groovy (Many modules)
Component2 moduleName1 moduleScript1.groovy moduleName2 moduleScript2.groovy Component2 moduleName1 moduleScript1.groovy moduleName2 moduleScript2.groovy
I have looked many sed commands but as I understand it is changing in one file not in all.我查看了许多 sed 命令,但据我所知,它不是在一个文件中更改。 Can someone help me with editing all files together.
有人可以帮我一起编辑所有文件吗?
I don't have any code specifically for this, but you could have another python script that opens each file in the folders, and checks specifically for the line of code that you want to change, after that you could have it either alert you of the line location or change it manually... The code might look something like this.我没有专门用于此的任何代码,但是您可以使用另一个 python 脚本打开文件夹中的每个文件,并专门检查要更改的代码行,然后您可以让它提醒您行位置或手动更改它...代码可能看起来像这样。
FILE_LIST = []
REPEAT (AMOUNT OF FILES)
OPEN(FILE) AS X
FILE_LIST APPEND X
REPEAT (RANGE(FILE_LIST))
IF (LINE YOU WANT TO CHANGE) IN FILE_LIST[FILE] THEN
ALERT
ELSE
CONTINUE
for r, d, f in os.walk(path):
for file in f:
if file.endswith('.grooviy'):
update_one_line_in(os.join(r, file))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.