使用组名称搜索并替换 UUID
我在以下文件中有组名称列表。
$ cat group_list.txt
member/brazil/linux/team
member/london/windows/team
member/china/bootloader/team
member/india/message/team
member/romania/mac/team
........
...........
然后我在许多 git 存储库中都有 groups
文件(采用下面给定的格式),我需要在所有存储库中搜索带有组名称的 groups 文件,例如 member/brazil/linux/ team
如果组名称存在于组文件中,则需要用新的 UUID
替换。
$ cat groups
# UUID Group Name
#
b16e145bac197a36802a31c5886ad726ee4f38c4 member/brazil/linux/team
使用每个组的以下命令,我可以获得其新 UUID
$ ssh -p 29418 review.example.com gerrit ls-groups -v | awk '-F\t' '$1 == "member/brazil/linux/team" {print $2}'
ef02b22ac4ce179a0064b1df2b326fd6b5dce514
一个组文件的预期输出:-
$ cat groups
# UUID Group Name
#
ef02b22ac4ce179a0064b1df2b326fd6b5dce514 member/brazil/linux/team
需要帮助以自动方式将我当前的每个 UUID 替换为新的 UUID。
@tshiono,请求的输出如下。
$ ssh -p 29418 review.example.com gerrit ls-groups -v
member/brazil/linux/team b16e145bac197a36802a31c5886ad726ee4f38c4 member/brazil/linux/team b16e145bac197a36802a31c5886ad726ee4f38c4 false
member/london/windows/team 3cab73598a48f443c8ca21fb77b1ea42ef00cbe6 member/london/windows/team 3cab73598a48f443c8ca21fb77b1ea42ef00cbe6 false
............
............................
I have list of group name in the following file.
$ cat group_list.txt
member/brazil/linux/team
member/london/windows/team
member/china/bootloader/team
member/india/message/team
member/romania/mac/team
........
...........
Then i have groups
file (in below given format) in many of our git repositories and i need to search in all repositories of groups file with the group name for example member/brazil/linux/team
if group name exists in group file, then it need to replace with new UUID
.
$ cat groups
# UUID Group Name
#
b16e145bac197a36802a31c5886ad726ee4f38c4 member/brazil/linux/team
With the below command for each group i get its new UUID
$ ssh -p 29418 review.example.com gerrit ls-groups -v | awk '-F\t' '$1 == "member/brazil/linux/team" {print $2}'
ef02b22ac4ce179a0064b1df2b326fd6b5dce514
Expected output for one groups file:-
$ cat groups
# UUID Group Name
#
ef02b22ac4ce179a0064b1df2b326fd6b5dce514 member/brazil/linux/team
Need help to replace each of my current UUIDs with the new ones in an automated way.
@tshiono, Requested output as follows.
$ ssh -p 29418 review.example.com gerrit ls-groups -v
member/brazil/linux/team b16e145bac197a36802a31c5886ad726ee4f38c4 member/brazil/linux/team b16e145bac197a36802a31c5886ad726ee4f38c4 false
member/london/windows/team 3cab73598a48f443c8ca21fb77b1ea42ef00cbe6 member/london/windows/team 3cab73598a48f443c8ca21fb77b1ea42ef00cbe6 false
............
............................
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请您尝试一下 bash 脚本:
使用提供的示例输出:
while
循环中读取ssh
命令的输出,将行拆分为字段,并将两个变量
group
和uuid
分配给第一个和第二个字段。然后将数组ary
分配给由group
索引的uuid
。如果 ssh 的输出包含多行(多个 group-uuid 对),则数组将保存尽可能多的值。ssh
的输出通过进程替换
送入while
循环语法为
< 的机制<(命令)
。while
循环处理文件groups
替换uuid
与在第一个循环中分配的
group
关联。groups
文件不会被覆盖。输出被重定向到一个新文件newgroups
。如果文件看起来正确,请使用mv -i newgroups groups
重命名。提前备份原groups
文件。Would you please try the bash script:
Output with the provided example:
ssh
command in thewhile
loop,splitting the line into fields and assigning two variables
group
anduuid
to the 1st and 2nd fields. Then an arrayary
is assigned touuid
indexed bygroup
. If the output ofssh
contains multiple lines (multiple group-uuid pairs), the array holds the values as many.ssh
is fed to thewhile
loop via theprocess substitution
mechanism with the syntax
< <(command)
.while
loop processes the filegroups
replacing theuuid
associated with
group
, which is assigned in the first loop.groups
file is not overwritten. The output is redirected to a new filenewgroups
. If the file looks correct, rename it withmv -i newgroups groups
. Backup the originalgroups
file in advance.