Answer the question
In order to leave comments, you need to log in
How to delete by pattern?
There is a text like
d-auth-service-5f5f466864-bdskb
demodent-api-gateway-677bf48f98-gmn2n
demomed-client-widget-6c58686f69-qvj9g
demomed-analysis-service-6f955bff79-cqjv9
was d emomed-analysis-service
Answer the question
In order to leave comments, you need to log in
Maybe someone will write more beautifully, it's interesting to see.
LIST="d-auth-service-5f5f466864-bdskb demodent-api-gateway-677bf48f98-gmn2n demomed-client-widget-6c58686f69-qvj9g"
for L in $LIST; do
echo "src: $L"
OIFS=$IFS; IFS="-"; N=($L); IFS=$OIFS; Z=${N[0]}
for ((I=1; $I < `expr ${#N[*]} - 2`; I=`expr $I + 1`)); do
Z=$Z-${N[$I]}
done
echo "result: $Z"
done
src: d-auth-service-5f5f466864-bdskb
result: d-auth-service
src: demodent-api-gateway-677bf48f98-gmn2n
result: demodent-api-gateway
src: demomed-client-widget-6c58686f69-qvj9g
result: demomed-client-widget
for L in $LIST; do
echo "src - $L"
Z=`echo $L | cut -f1-3 -d'-'`
echo "result - $Z"
done
echo 'd-auth-service-5f5f466864-bdskb
demodent-api-gateway-677bf48f98-gmn2n
demomed-client-widget-6c58686f69-qvj9g' | sed -r 's/(.+)-{10}-{5}$/\1/'
Well, since such a booze has gone
LIST="d-auth-service-5f5f466864-bdskb demodent-api-gateway-677bf48f98-gmn2n demomed-client-widget-6c58686f69-qvj9g"
for L in $LIST; do
echo ${L%-*-*}
done
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question