hi group,
How can I count total number of 5's which are continuous in the end. i.e. in the below string, the o/p should be 4
I just know to calculate total number of 5's
$ echo "95952325555" | awk -F "5" '{print NF-1}'
6
hi group,
How can I count total number of 5's which are continuous in the end. i.e. in the below string, the o/p should be 4
I just know to calculate total number of 5's
$ echo "95952325555" | awk -F "5" '{print NF-1}'
6
# echo "95952325555" | awk -F"[^5]" '{print length($NF)}'
4
# echo "95952355555" | awk -F"[^5]" '{print length($NF)}'
5
# echo "959523554555" | awk -F"[^5]" '{print length($NF)}'
3
hi,
i think perl is easy.
below code is more flexiable that whatever your last consecutive char is, it will give out the repeatation.
my $str="124334456777";
my @arr=split("",$str);
my $n=pop @arr;
my $cnt=1;
while($#arr >= 0){
if ((pop @arr) eq $n ){
$cnt++;
}
else{
print $cnt;
exit;
}
}
Or:
% perl -le'print length((split/[^5]/,shift)[-1])' 95952325555
4
% perl -le'print length((split/[^5]/,shift)[-1])' 959523255555
5
% perl -le'print length((split/[^5]/,shift)[-1])' 9595232555
3