次のスクリプトを使用してデータをファイルに収集しています。
while IFS= read -r line
do
echo "$line"
echo -e "$line-new" >>newfile.txt
done <"file.txt
」
新しいファイルには次のデータが含まれます。
gl-system-events_1
gl-events_2
gl-system-events_0
gl-events_6
gl-events_1
gl-events_5
gl-system-events_6
gl-system-events_4
gl-events_3
gl-system-events_2
gl-system-events_5
gl-events_0
次に、各行を順次読み込み、その文字列に対して特定のコマンドを実行するスクリプトを作成したいと思います。
たとえば、gl-system-events_2ジョブを識別した場合はコマンドAを実行し、gl-events_0を識別するとコマンドBを実行し、他のジョブを識別した場合はコマンドCを実行する必要があります。
ifまたは他の方法を使用してそれらを保存するのに役立ちますか?
ありがとう、サム
ベストアンサー1
スイッチを使用できますcase
。それは次のとおりです。
while IFS= read -r line
do
case $line in
gl-system-events_2)
commandA
;;
gl-events_0)
commandB
;;
*)
commandC
;;
esac
done