-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathqksearch.sh
executable file
·65 lines (57 loc) · 2.06 KB
/
qksearch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# Check if both arguments are provided
if [ $# -lt 2 ]; then
echo "Usage: $0 <log_file> <search_term>"
exit 1
fi
# Get the last argument as search_term
search_term="${@: -1}"
# Remove the last argument, leaving only file paths
set -- "${@:1:$(($#-1))}"
# Use awk to search for the term and extract relevant API URLs and IDs
awk -v term="$search_term" '
function print_result() {
if (block_url != "" && block_id != "" && found_in_current_block) {
if (!(block_id in printed)) {
printf "URL: %s, ID: %s\n", block_url, block_id
printed[block_id] = 1
}
}
}
/^💡/ {
# New log entry starts
found_in_current_block = 0
if ($0 ~ /#[0-9]+/) {
match($0, /#([0-9]+)/)
block_id = substr($0, RSTART+1, RLENGTH-1)
# Try to extract URL - first check for HTTP method
if ($0 ~ /(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)/) {
match($0, /(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)/)
method_pos = RSTART + RLENGTH
rest = substr($0, method_pos)
if (match(rest, /[[:space:]]+https?:\/\/[^[:space:]]+/)) {
block_url = substr(rest, RSTART+1, RLENGTH-1)
gsub(/["\047\s,}]$/, "", block_url)
}
}
# If no HTTP method found, try to find URL in response line
else if ($0 ~ /[0-9]+ https?:\/\//) {
match($0, /[0-9]+ (https?:\/\/[^[:space:]]+)/)
if (RSTART) {
block_url = substr($0, RSTART + RLENGTH - match($0, /https:\/\/[^[:space:]]+/), match($0, /https:\/\/[^[:space:]]+/))
gsub(/["\047\s,}]$/, "", block_url)
}
}
}
}
tolower($0) ~ tolower(term) {
found_in_current_block = 1
print_result()
}
/^$/ {
# Empty line marks end of a block
block_url = ""
block_id = ""
found_in_current_block = 0
}
' "$@"