bashの下では、やその他のような外部ツール ( forks ) を必要としないこの要件を実行する方法があります。sed
awk
i=0;
while read string ;do
((i++))
int=${string#*Int-}
int=(${int//[a-z_-]/ })
exp=${string#*Exp-}
exp=(${exp//[a-z_-]/ })
var=(${string//[a-z_-]/ })
printf "Line #%2d contain: Int: %6s, Exp: %6s in %2d values: <%s>\n" \
$i "$int" "$exp" ${#var[@]} "${var[*]}"
done <<<'
newSetupSL5_snolab_Int-300_Exp-10000_3515
snolab_Int-300_Exp-10000_1185
newSetupSL5_snolab_Int-300_Exp-5000_2522
'
Line # 1 contain: Int: , Exp: in 0 values: <>
Line # 2 contain: Int: 300, Exp: 10000 in 4 values: <5 300 10000 3515>
Line # 3 contain: Int: , Exp: in 0 values: <>
Line # 4 contain: Int: 300, Exp: 10000 in 3 values: <300 10000 1185>
Line # 5 contain: Int: , Exp: in 0 values: <>
Line # 6 contain: Int: 300, Exp: 5000 in 4 values: <5 300 5000 2522>
Line # 7 contain: Int: , Exp: in 0 values: <>
またはExp-とInt-の両方 を含む行をフィルタリングします。
i=0
while read string ;do
if [ "$string" != "${string#*Int-*Exp-}" ];then
((i++))
int=${string#*Int-}
int=(${int//[a-z_-]/ })
exp=${string#*Exp-}
exp=(${exp//[a-z_-]/ })
var=(${string//[a-z_-]/ })
printf "Line #%2d contain: Int: %6s, Exp: %6s in %2d values: <%s>\n" \
$i "$int" "$exp" ${#var[@]} "${var[*]}"
fi
done <<<'
newSetupSL5_snolab_Int-300_Exp-10000_3515
snolab_Int-300_Exp-10000_1185
newSetupSL5_snolab_Int-300_Exp-5000_2522
'
Line # 1 contain: Int: 300, Exp: 10000 in 4 values: <5 300 10000 3515>
Line # 2 contain: Int: 300, Exp: 10000 in 3 values: <300 10000 1185>
Line # 3 contain: Int: 300, Exp: 5000 in 4 values: <5 300 5000 2522>