Skip to content

Commit e70bfc8

Browse files
authored
Update combined.sh
Corrected this: output_file="$(pwd)/combined_log.txt" # Using current directory for input file filtered_output_file="$(pwd)/filtered_log.txt" # Using current directory for output file Now it no longer assumes home for output directory.
1 parent 48a7ce9 commit e70bfc8

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

‎log-helper/combined.sh‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

3-
output_file="$HOME/combined_log.txt"
4-
filtered_output_file="$HOME/filtered_log.txt"
3+
output_file="$(pwd)/combined_log.txt" # Using current directory for input file
4+
filtered_output_file="$(pwd)/filtered_log.txt" # Using current directory for output file
55
summary_file="summary_temp.txt"
66
focused_summary_file="focused_summary_temp.txt"
77

@@ -181,6 +181,14 @@ case $choice in
181181
esac
182182

183183
if [ "$choice" == "4" ]; then
184+
echo "Looking for file called combined_log.txt in current directory..."
185+
output_file="$(pwd)/combined_log.txt" # Change to current directory
186+
if [ ! -f "$output_file" ]; then
187+
echo "File not found: $output_file"
188+
exit 1
189+
fi
190+
echo "File found. Proceeding with filtering options."
191+
184192
echo "Choose filtering option:"
185193
echo "1. Grep for a key phrase"
186194
echo "2. Grep for a keyword"
@@ -190,26 +198,29 @@ if [ "$choice" == "4" ]; then
190198
1)
191199
echo "Enter the key phrase to grep for:"
192200
read key_phrase
193-
grep -i -B 3 -A 5 "$key_phrase" "$output_file" > "$filtered_output_file"
201+
key_phrase=$(echo "$key_phrase" | xargs) # Trim whitespace
202+
grep -F -i -B 3 -A 5 "$key_phrase" "$output_file" > "$filtered_output_file"
194203
;;
195204
2)
196205
echo "Enter the keyword to grep for:"
197206
read keyword
198-
grep -i -w -B 3 -A 5 "$keyword" "$output_file" > "$filtered_output_file"
207+
keyword=$(echo "$keyword" | xargs) # Trim whitespace
208+
grep -w -i -B 3 -A 5 "$keyword" "$output_file" > "$filtered_output_file"
199209
;;
200210
*)
201211
echo "Invalid choice. No filtering applied."
202212
exit 1
203213
;;
204214
esac
205215

216+
if [ ! -s "$filtered_output_file" ]; then
217+
echo "No matches found. Filtered log file is empty."
218+
exit 1
219+
fi
220+
206221
echo -e "\n${BOLD}Filtered log saved in $filtered_output_file${RESET}"
207222
line_count=$(wc -l < "$filtered_output_file")
208223
echo -e "${BOLD}Total lines in filtered output: $line_count${RESET}"
209-
else
210-
echo -e "\n${BOLD}Log collection complete. Results saved in $output_file${RESET}"
211-
line_count=$(wc -l < "$output_file")
212-
echo -e "${BOLD}Total lines in output: $line_count${RESET}"
213224
fi
214225

215226
# Remove temporary files

0 commit comments

Comments
 (0)