有多个文件(1000个文件)需要进行此更改;手动执行是不可行的 - 有人可以建议如何在Unix / Linux shell脚本中进行操作吗?
要求:
对于CONF_CATALOG_MULTI_SERVER_HOST_SECONDARY和CONF_SEARCH_MULTI_SERVER_HOST_SECONDARY l2cache[25-48]
,我需要更改[13-24]
。
示例:edc-v1-l2cache25
此更改为edc-v1-l2cache13
,edc-v1-l2cache26
更改为edc-v1-l2cache14
,依此类推,直到36更改为24并删除其余37-48。
对于CONF_SEARCH_MULTI_SERVER_HOST和CONF_CATALOG_MULTI_SERVER_HOST l2cache[1-24]
,我需要更改为[1-12]
即需要删除l2cache[13-24]
,CONF_CATALOG_MULTI_SERVER_HOST和CONF_SEARCH_MULTI_SERVER_HOST
edc-v1-l2cache[1-12]
醇>
示例/ INPUT数据:
CONF_CATALOG_MULTI_SERVER_HOST_SECONDARY=edc-v1-l2cache25 ,edc-v1-l2cache26 ,edc-v1-l2cache27 ,edc-v1-l2cache28 ,edc-v1-l2cache29 ,edc-v1-l2cache30 ,edc-v1-l2cache31 ,edc-v1-l2cache32 ,edc-v1-l2cache33 ,edc-v1-l2cache34 ,edc-v1-l2cache35 ,edc-v1-l2cache36 ,edc-v1-l2cache37 ,edc-v1-l2cache38 ,edc-v1-l2cache39 ,edc-v1-l2cache40 ,edc-v1-l2cache41 ,edc-v1-l2cache42 ,edc-v1-l2cache43 ,edc-v1-l2cache44 ,edc-v1-l2cache45 ,edc-v1-l2cache46 ,edc-v1-l2cache47 ,edc-v1-l2cache48
CONF_SEARCH_MULTI_SERVER_HOST_SECONDARY=edc-v1-l2cache25 ,edc-v1-l2cache26 ,edc-v1-l2cache27 ,edc-v1-l2cache28 ,edc-v1-l2cache29 ,edc-v1-l2cache30 ,edc-v1-l2cache31 ,edc-v1-l2cache32 ,edc-v1-l2cache33 ,edc-v1-l2cache34 ,edc-v1-l2cache35 ,edc-v1-l2cache36 ,edc-v1-l2cache37 ,edc-v1-l2cache38 ,edc-v1-l2cache39 ,edc-v1-l2cache40 ,edc-v1-l2cache41 ,edc-v1-l2cache42 ,edc-v1-l2cache43 ,edc-v1-l2cache44 ,edc-v1-l2cache45 ,edc-v1-l2cache46 ,edc-v1-l2cache47 ,edc-v1-l2cache48
CONF_CATALOG_MULTI_SERVER_HOST=edc-v1-l2cache1 ,edc-v1-l2cache2 ,edc-v1-l2cache3 ,edc-v1-l2cache4 ,edc-v1-l2cache5 ,edc-v1-l2cache6 ,edc-v1-l2cache7 ,edc-v1-l2cache8 ,edc-v1-l2cache9 ,edc-v1-l2cache10 ,edc-v1-l2cache11 ,edc-v1-l2cache12 ,edc-v1-l2cache13 ,edc-v1-l2cache14 ,edc-v1-l2cache15 ,edc-v1-l2cache16 ,edc-v1-l2cache17 ,edc-v1-l2cache18 ,edc-v1-l2cache19 ,edc-v1-l2cache20 ,edc-v1-l2cache21 ,edc-v1-l2cache22 ,edc-v1-l2cache23 ,edc-v1-l2cache24
CONF_SEARCH_MULTI_SERVER_HOST=edc-v1-l2cache1 ,edc-v1-l2cache2 ,edc-v1-l2cache3 ,edc-v1-l2cache4 ,edc-v1-l2cache5 ,edc-v1-l2cache6 ,edc-v1-l2cache7 ,edc-v1-l2cache8 ,edc-v1-l2cache9 ,edc-v1-l2cache10 ,edc-v1-l2cache11 ,edc-v1-l2cache12 ,edc-v1-l2cache13 ,edc-v1-l2cache14 ,edc-v1-l2cache15 ,edc-v1-l2cache16 ,edc-v1-l2cache17 ,edc-v1-l2cache18 ,edc-v1-l2cache19 ,edc-v1-l2cache20 ,edc-v1-l2cache21 ,edc-v1-l2cache22 ,edc-v1-l2cache23 ,edc-v1-l2cache24
输出数据:
CONF_CATALOG_MULTI_SERVER_HOST_SECONDARY=edc-v1-l2cache13 ,edc-v1-l2cache14 ,edc-v1-l2cache15 ,edc-v1-l2cache16 ,edc-v1-l2cache17 ,edc-v1-l2cache18 ,edc-v1-l2cache19 ,edc-v1-l2cache20 ,edc-v1-l2cache21 ,edc-v1-l2cache22 ,edc-v1-l2cache23 ,edc-v1-l2cache24
CONF_SEARCH_MULTI_SERVER_HOST_SECONDARY=edc-v1-l2cache13 ,edc-v1-l2cache14 ,edc-v1-l2cache15 ,edc-v1-l2cache16 ,edc-v1-l2cache17 ,edc-v1-l2cache18 ,edc-v1-l2cache19 ,edc-v1-l2cache20 ,edc-v1-l2cache21 ,edc-v1-l2cache22 ,edc-v1-l2cache23 ,edc-v1-l2cache24
CONF_CATALOG_MULTI_SERVER_HOST=edc-v1-l2cache1 ,edc-v1-l2cache2 ,edc-v1-l2cache3 ,edc-v1-l2cache4 ,edc-v1-l2cache5 ,edc-v1-l2cache6 ,edc-v1-l2cache7 ,edc-v1-l2cache8 ,edc-v1-l2cache9 ,edc-v1-l2cache10 ,edc-v1-l2cache11 ,edc-v1-l2cache12
CONF_SEARCH_MULTI_SERVER_HOST=edc-v1-l2cache1 ,edc-v1-l2cache2 ,edc-v1-l2cache3 ,edc-v1-l2cache4 ,edc-v1-l2cache5 ,edc-v1-l2cache6 ,edc-v1-l2cache7 ,edc-v1-l2cache8 ,edc-v1-l2cache9 ,edc-v1-l2cache10 ,edc-v1-l2cache11 ,edc-v1-l2cache12
答案 0 :(得分:1)
所以,这些名字是恶魔般长的!
根据输出,对于CSMSHS和CCMSHS条目,您需要更改内容,以便重新组织25-48的条目,以便有12个条目的值为13-24,其他12个条目将被删除。
同样,对于CSMSH和CCMSH条目,您要删除值为13-24的条目。
据推测,您不必担心文件中的不规则条目;它们现在都是一致的,之后应该都是一致的。
坦率地说,最简单的方法是创建替换字符串并使用相对简单的搜索来识别需要更改的行(确保更改是幂等的;将脚本重新应用到转换后的文件不会更改文件第二次)。我发现空间逗号符号令人反感;在我工作的圈子里,应该是逗号空间。但是,我们可以单独留下它。
我使用Perl,但是如果你愿意的话可以使用Awk,而且Python也可以轻松地使用它。
#!/usr/bin/perl
use strict;
use warnings;
my $base = "edc-v1-l2cache";
my $secondary = "";
my $pad = "";
for (my $i = 13; $i <= 24; $i++)
{
$secondary .= $pad . $base . $i;
$pad = " ,"; # ", "!
}
my $primary = "";
$pad = "";
for (my $i = 1; $i <= 12; $i++)
{
$primary .= $pad . $base . $i;
$pad = " ,"; # ", "!
}
while (<>)
{
s//$1$secondary/
if (m/(CONF_(?:CATALOG|SEARCH)_MULTI_SERVER_HOST_SECONDARY=)${base}25 ,.*${base}48$/);
s//$1$primary/
if (m/(CONF_(?:CATALOG|SEARCH)_MULTI_SERVER_HOST=)${base}1 ,.*${base}24$/);
print;
}
如果某些条目可能丢失且需要特别处理,则必须更加努力。