我们可以将正则表达式与 cleartool 命令一起使用吗?
Can we use regex with cleartool commands?
我正在使用以下命令检索基线。
cleartool lsbl -fmt "%n\n" -comp comp_name@\vob_name -stream stream_name@\vob_name
我正在寻找一种方法来显示在数值上等于/小于特定给定基线的基线。有什么办法可以实现吗?
情况 1:如果输出为
abc_6.2168
abc_7.4587
abc_8.2950
abc_9.3032
如果我想显示在数值上等于/小于(并且最接近)abc_8 的基线。因此,案例 1 中的预期结果应为:abc_8.2950。
情况 2:如果输出为
abc_6.2168
abc_7.4587
abc_9.3032
预期结果应为:abc_7.4587
注意:在 Groovy(Jenkins 管道)
上尝试此操作
Is there any way to achieve it?
不能单独使用 ClearCase/cleartool
,这意味着您需要解析其输出,这取决于您的 OS/shell。
类似于 Windows CMD shell,:
cleartool lsbl ... | sort -V |awk 'BEGIN{a=[=10=];FS="._"} ^< 9{print [=10=];}'|tail -1
(需要 ^<
来转义 <
,并防止 CMD 将其解释为重定向)
use strict;
use warnings;
use DBI;
my $bsl_find = $ARGV[0]; #baseline build package name
my $bsl;
my $c=0;
my $mat;
my $previous_str = q{};
my $final_baseline;
my $prev_num_count=1;
my $prev_num_len=1;
my $split_strng;
my $baseline_var = q{};
my $baseline_file;
my $all_baseline_file = $ARGV[1]; #file which contains the list of all retreived baselines as per ARGV[0]
my $app = $ARGV[2]; #the name of the application for which baseline is to be selected
my $filename = 'D:\baseline_'.$app.'\'.'new_'.$all_baseline_file.'.txt';
$baseline_file = 'D:\baseline_'.$app.'\'.'final_'.$all_baseline_file.'.txt';
$all_baseline_file = 'D:\baseline_'.$app.'\'.$all_baseline_file.'.txt';
open(my $fh, '<:encoding(UTF-8)',$filename)
or die "Could not open file '$filename' $!";
while (my $strng = <$fh>) {
chomp $strng;
#print "The line is : $strng \n";
$strng=~ s/^\s+|\s+$//;
#print " \n strng after trim is $strng.";
my $num_count = (split '_', $strng)[-1];
my $num_count_bsl_param = (split '_', $bsl_find)[-1];
my $num_len = length ($num_count);
my $num_len_bsl_param = length ($num_count_bsl_param);
my $a = substr($bsl_find, -$num_len_bsl_param);
my $b = substr($strng, -$num_len);
$split_strng = '_'.$a;
my ($substrng) = split /$split_strng/, $bsl_find;
if ($substrng =~ m/([^\_]+)$/)
{
$substrng=;
}
if ( ($a == $b) && (index($strng, $substrng) != -1) )
{
print "\n Match found";
$mat = $strng;
print "\n baseline found is : $mat";
$final_baseline = $mat;
print "\n final bsl is $bsl_find";
$baseline_var = $strng;
#exit 0;
goto label;
}
elsif ( ($a < $b) && (index($strng, $substrng) != -1) )
{
if ( (grep{/$bsl_find/} $filename) && ($previous_str eq "") ){
print "\n final baseline decided : $bsl_find";
$baseline_var = $bsl_find;
goto label;
}
elsif ( ($previous_str ne "") )
{
print "\n final baseline is ...: $previous_str";
$baseline_var = $previous_str;
goto label;
}
}
elsif ( ($a < $b) && ($previous_str ne "") && (index($strng, $substrng) != -1) )
{
if ( ($a > $c) && (index($previous_str, $substrng) != -1) )
{
print "\n baseline found is : $previous_str";
$final_baseline = $previous_str;
print " \n final is $final_baseline";
$baseline_var = $previous_str;
goto label;
}
}
elsif ( ($a < $b) && (index($bsl_find, $substrng) != -1) && ($previous_str ne "") && (index($previous_str, $substrng) == -1) )
{
print "\n Baseline not found of type $bsl_find.... final baseline is : $previous_str";
$baseline_var = $previous_str;
goto label;
}
close(fh);
}
if ($baseline_var eq "")
{
open my $fh ,"<",$filename;
my $last_line;
$last_line = $_,while (<$fh>);
print $last_line;
print " \n Baseline is $last_line";
$baseline_var = $last_line;
goto label;
close(fh);
}
label:
print " \n\n Writing $baseline_var to $baseline_file...";
#$baseline_var = $baseline_var.'.';
$baseline_var=~ s/^\s+|\s+$//;
print " \n \n baseline_var is $baseline_var. ";
unlink $baseline_file;
open(my $fh, '<:encoding(UTF-8)',$all_baseline_file)
or die "Could not open file '$all_baseline_file' $!";
while (my $word = <$fh>) {
chomp $word;
#print "\n word is $word.";
if ( $word =~ /\./ )
{
if( $word =~ m/$baseline_var\./ )
{
print "\n found $baseline_var. in $word";
open(FH1, '>', $baseline_file) or die $!;
print FH1 "$word";
}
}
else
{
if( $word eq $baseline_var )
{
print "\n found $baseline_var. in $word";
open(FH1, '>', $baseline_file) or die $!;
print FH1 "$word";
}
}
close(fh);
}
close(FH1);
}
我正在使用以下命令检索基线。
cleartool lsbl -fmt "%n\n" -comp comp_name@\vob_name -stream stream_name@\vob_name
我正在寻找一种方法来显示在数值上等于/小于特定给定基线的基线。有什么办法可以实现吗?
情况 1:如果输出为
abc_6.2168
abc_7.4587
abc_8.2950
abc_9.3032
如果我想显示在数值上等于/小于(并且最接近)abc_8 的基线。因此,案例 1 中的预期结果应为:abc_8.2950。
情况 2:如果输出为
abc_6.2168
abc_7.4587
abc_9.3032
预期结果应为:abc_7.4587
注意:在 Groovy(Jenkins 管道)
上尝试此操作Is there any way to achieve it?
不能单独使用 ClearCase/cleartool
,这意味着您需要解析其输出,这取决于您的 OS/shell。
类似于 Windows CMD shell,
cleartool lsbl ... | sort -V |awk 'BEGIN{a=[=10=];FS="._"} ^< 9{print [=10=];}'|tail -1
(需要 ^<
来转义 <
,并防止 CMD 将其解释为重定向)
use strict;
use warnings;
use DBI;
my $bsl_find = $ARGV[0]; #baseline build package name
my $bsl;
my $c=0;
my $mat;
my $previous_str = q{};
my $final_baseline;
my $prev_num_count=1;
my $prev_num_len=1;
my $split_strng;
my $baseline_var = q{};
my $baseline_file;
my $all_baseline_file = $ARGV[1]; #file which contains the list of all retreived baselines as per ARGV[0]
my $app = $ARGV[2]; #the name of the application for which baseline is to be selected
my $filename = 'D:\baseline_'.$app.'\'.'new_'.$all_baseline_file.'.txt';
$baseline_file = 'D:\baseline_'.$app.'\'.'final_'.$all_baseline_file.'.txt';
$all_baseline_file = 'D:\baseline_'.$app.'\'.$all_baseline_file.'.txt';
open(my $fh, '<:encoding(UTF-8)',$filename)
or die "Could not open file '$filename' $!";
while (my $strng = <$fh>) {
chomp $strng;
#print "The line is : $strng \n";
$strng=~ s/^\s+|\s+$//;
#print " \n strng after trim is $strng.";
my $num_count = (split '_', $strng)[-1];
my $num_count_bsl_param = (split '_', $bsl_find)[-1];
my $num_len = length ($num_count);
my $num_len_bsl_param = length ($num_count_bsl_param);
my $a = substr($bsl_find, -$num_len_bsl_param);
my $b = substr($strng, -$num_len);
$split_strng = '_'.$a;
my ($substrng) = split /$split_strng/, $bsl_find;
if ($substrng =~ m/([^\_]+)$/)
{
$substrng=;
}
if ( ($a == $b) && (index($strng, $substrng) != -1) )
{
print "\n Match found";
$mat = $strng;
print "\n baseline found is : $mat";
$final_baseline = $mat;
print "\n final bsl is $bsl_find";
$baseline_var = $strng;
#exit 0;
goto label;
}
elsif ( ($a < $b) && (index($strng, $substrng) != -1) )
{
if ( (grep{/$bsl_find/} $filename) && ($previous_str eq "") ){
print "\n final baseline decided : $bsl_find";
$baseline_var = $bsl_find;
goto label;
}
elsif ( ($previous_str ne "") )
{
print "\n final baseline is ...: $previous_str";
$baseline_var = $previous_str;
goto label;
}
}
elsif ( ($a < $b) && ($previous_str ne "") && (index($strng, $substrng) != -1) )
{
if ( ($a > $c) && (index($previous_str, $substrng) != -1) )
{
print "\n baseline found is : $previous_str";
$final_baseline = $previous_str;
print " \n final is $final_baseline";
$baseline_var = $previous_str;
goto label;
}
}
elsif ( ($a < $b) && (index($bsl_find, $substrng) != -1) && ($previous_str ne "") && (index($previous_str, $substrng) == -1) )
{
print "\n Baseline not found of type $bsl_find.... final baseline is : $previous_str";
$baseline_var = $previous_str;
goto label;
}
close(fh);
}
if ($baseline_var eq "")
{
open my $fh ,"<",$filename;
my $last_line;
$last_line = $_,while (<$fh>);
print $last_line;
print " \n Baseline is $last_line";
$baseline_var = $last_line;
goto label;
close(fh);
}
label:
print " \n\n Writing $baseline_var to $baseline_file...";
#$baseline_var = $baseline_var.'.';
$baseline_var=~ s/^\s+|\s+$//;
print " \n \n baseline_var is $baseline_var. ";
unlink $baseline_file;
open(my $fh, '<:encoding(UTF-8)',$all_baseline_file)
or die "Could not open file '$all_baseline_file' $!";
while (my $word = <$fh>) {
chomp $word;
#print "\n word is $word.";
if ( $word =~ /\./ )
{
if( $word =~ m/$baseline_var\./ )
{
print "\n found $baseline_var. in $word";
open(FH1, '>', $baseline_file) or die $!;
print FH1 "$word";
}
}
else
{
if( $word eq $baseline_var )
{
print "\n found $baseline_var. in $word";
open(FH1, '>', $baseline_file) or die $!;
print FH1 "$word";
}
}
close(fh);
}
close(FH1);
}