Delete OS/bash/q5.sh
This commit is contained in:
parent
726fca7002
commit
3a41fa1686
@ -1,38 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
num_patterns=$(( $# ))
|
||||
patterns=("${@:1:num_patterns}")
|
||||
input_file="${!num_patterns}"
|
||||
|
||||
|
||||
while true;do
|
||||
echo "a. Search the patterns in the given input file."
|
||||
echo "b. Delete all occurrences of the pattern in the given input file."
|
||||
echo "c. Exit"
|
||||
|
||||
read choice
|
||||
|
||||
case "$choice" in
|
||||
a)
|
||||
echo "Searching patterns in $input_file:"
|
||||
for pattern in "${patterns[@]}"; do
|
||||
grep "$pattern" "$input_file"
|
||||
done
|
||||
;;
|
||||
b)
|
||||
echo "Deleting occurrences of patterns in $input_file:"
|
||||
for pattern in "${patterns[@]}"; do
|
||||
sed -i "s/$pattern//g" "$input_file"
|
||||
done
|
||||
echo "Occurrences deleted."
|
||||
;;
|
||||
c)
|
||||
echo "Exiting..."
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Invalid choice. Please enter 'a', 'b', or 'c'."
|
||||
;;
|
||||
esac
|
||||
|
||||
done
|
Loading…
x
Reference in New Issue
Block a user