executing commands from a file after filtering

Hi,
I have a question here. Please suggest.

I have a file which has some unix commands to be executed through shell scripting. The number of commands will be different every time based on some external instructions i received. I manually keep the instuctions in this file.

i need to execute commands only which starts with PRE# how to do this in shell scripting.

for example,
PRE#cd /tmp
PRE#touch file.txt
POST#cp -p file.txt file1.txt

in the above, i want to execute only the commands that start with PRE#

One way:

awk -F"#" '/^PRE/{print $2}' file | sh
1 Like