File tree Expand file tree Collapse file tree 1 file changed +59
-1
lines changed
Introduction to Bash Scripting Expand file tree Collapse file tree 1 file changed +59
-1
lines changed Original file line number Diff line number Diff line change 8787- Use an IF statement and grep to check if the sfile variable contains SRVM_ AND vpt inside.
8888- Inside the IF statement, move matching files to the good_logs/ directory.
8989- Try your script on all of the files in the directory (that is, run it four times - once for each file). It should move only one of them.
90- """
90+ """
9191# Create variable from first ARGV element
9292sfile = $1
9393
184184
185185Answer : It will run forever because emp_num isn't incremented inside the loop.
186186"""
187+
188+ """
189+ ### Cleaning up a directory
190+
191+ Instructions
192+
193+ - Use a FOR statement to loop through (using glob expansion) files that end in .py in robs_files/.
194+ - Use an IF statement and grep (remember the 'quiet' flag?) to check if RandomForestClassifier is in the file. Don't use a shell-within-a-shell here.
195+ - Move the Python files that contain RandomForestClassifier into the to_keep/ directory.
196+ """
197+ # Create a FOR statement on files in directory
198+ for file in robs_files / * .py
199+ do
200+ # Create IF statement using grep
201+ if grep - q 'RandomForestClassifier' $file ; then
202+ # Move wanted files to to_keep/ folder
203+ mv $file to_keep /
204+ fi
205+ done
206+
207+
208+ repl :~ / workspace $ cd / home / repl / workspace
209+ repl :~ / workspace $ bash script .sh
210+
211+ """
212+ *** CASE statements
213+ *** basic syntax
214+ >>>>>> case 'something' in
215+
216+ *** regex for pattern
217+ >>>>>> Air* : 'starts w/ Air'
218+ >>>>>> *hat* : 'contains hat'
219+
220+ ***syntax
221+ case 'something' in
222+ PATTERN1)
223+ COMMAND1;;
224+ PATTERN2)
225+ COMMAND2;;
226+ *)
227+ DEFAULT COMMAND;;
228+ esac
229+
230+ eg: #new case statement
231+ case $(cat $1) in
232+ *Sydney*)
233+ mv $1 sydney/ ;;
234+ *melbourne*|*brisbane*)
235+ rem $1 ;;
236+ *canberra*)
237+ mv $1 "IMPORTANT_$1" ;;
238+ *)
239+ echo "no cities found!" ;;
240+ esac
241+ """
242+
243+
244+
You can’t perform that action at this time.
0 commit comments