0

I am collecting data to one file with below script

while IFS= read -r line
do
echo "$line"
echo -e "$line-new" >>newfile.txt

done <"file.txt

"

new file has below data

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

now I want to write script that will read each line in sequence and run specific command for that string

for example if its identify work gl-system-events_2 it should run command A, if its identify gl-events_0 it should run command B, if its identify something else it should run command C

can you help me how I can use if or any other method to archive this.

Regards, SAM

1 Answer 1

2

You can use case switch. Something like:

while IFS= read -r line
do
   case $line in
     gl-system-events_2)
        commandA
        ;;
     gl-events_0)
        commandB
        ;;
     *)
        commandC
        ;;
    esac
done
   
1
  • Thank you White Owl, it helped me to get the desired result. Thank you once again.
    – Samurai
    Apr 29 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.