Skip to content

Commit d012283

Browse files
authored
Update III Control Statements in Bash Scripting.py
1 parent 3d00faa commit d012283

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Introduction to Bash Scripting/III Control Statements in Bash Scripting.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,37 @@
273273
"""
274274
### Moving model results with CASE
275275
276+
Your task is to use a CASE statement to move the tree-based models (Random Forest, GBM, and XGBoost)
277+
to the tree_models/ folder, and delete all other models (KNN and Logistic).
278+
276279
Instructions
277280
278281
- Use a FOR statement to loop through (using glob expansion) files in model_out/.
279282
- Use a CASE statement to match on the contents of the file (we will use cat and shell-within-a-shell to get the contents to match against). It must check if the
280283
text contains a tree-based model name and move to tree_models/, otherwise delete the file.
281284
- Create a default match that prints out Unknown model in FILE where FILE is the filename then run your script.
282285
"""
286+
# Use a FOR loop for each file in 'model_out/'
287+
for file in model_out/*
288+
do
289+
# Create a CASE statement for each file's contents
290+
case $(cat $file) in
291+
# Match on tree and non-tree models
292+
*"Random Forest"*|*GBM*|*XGBoost*)
293+
mv $file tree_models/ ;;
294+
*KNN*|*Logistic*)
295+
rm $file ;;
296+
# Create a default
297+
*)
298+
echo "Unknown model in $file" ;;
299+
esac
300+
done
301+
302+
"""
303+
### Finishing a CASE statement
304+
305+
-What is the correct way to finish a CASE statement?
306+
Answer the question
307+
308+
Answer : esac
309+
"""

0 commit comments

Comments
 (0)