I would like replace below input about storage disk to an output in below presented format: Below script is almost working for me. But it doesn't work for T0. It seems is there problem with proper read 0s at the end of number in 'replaceTier' function.
Could you somebody assist me to correct it? Thanks in advance.
**INPUT IN FILE:**
displayName=00:19:78
sizeInKB=26214720
dpPoolID=1
displayName=00:FE:B0
sizeInKB=2251536384
dpPoolID=110
displayName=00:FE:B1
sizeInKB=2251536384
dpPoolID=110
**EXPECTED OUTPUT:**
1978,T1
FEB0,T0
FEB1,T0
replaceTier=(
{1,11,12,13,14,15,16,17,18,19,51,61,71,81,100}:T1
{2,21,22,23,24}:T2
3:T3
{10,110}:T0
90:SVC_T1
91:SVC_T2
92:SVC_T1
)
#
while read -r name serial model uid
do
cat "$DIR"/"$name"_disks.log | grep -v 'sizeInKB' | cut -d "=" -f2 | sed 's/\://g' | xargs -n2 | sed 's/\ /\,/g' | cut -c 3- | grep -v ',-1' > "$DIR"/"$name"_output.log
for row in "${replaceTier[@]}"; do
original="$(echo $row | cut -d: -f1)";
new="$(echo $row | cut -d: -f2)";
sed -i -e "s/,${original}.*/,${new}/g" "$DIR"/"$name"_output.log;
done
done < /storage/logs/HDSlist.txt
.*
. With the.*
a number like,110
will match,1.*
which will get translated to T1. Alternatively, orderreplaceTier
such that longer prefixes (like110
) appear before shorter ones (like11
and1
.)$
, that way it will only replace when it's an exact match. Reordering it so longer prefixes are substituted first would also have helped.