-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathfix_dashboard_titles.sh
More file actions
executable file
·60 lines (51 loc) · 1.65 KB
/
fix_dashboard_titles.sh
File metadata and controls
executable file
·60 lines (51 loc) · 1.65 KB
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
#!/bin/bash
# Function to fix dashboard title
fix_dashboard_title() {
local file="$1"
local temp_file="${file}.tmp"
# Process the file line by line
while IFS= read -r line || [[ -n "$line" ]]; do
if echo "$line" | jq -e 'select(.type == "dashboard")' > /dev/null 2>&1; then
# It's a dashboard object, update the title
updated_line=$(echo "$line" | jq -c '
if .attributes.title and (.attributes.title | startswith("1x-") | not) then
.attributes.title = "1x-" + .attributes.title
else
.
end
')
echo "$updated_line" >> "$temp_file"
else
# Not a dashboard object, keep the line as is
echo "$line" >> "$temp_file"
fi
done < "$file"
# Replace the original file with the updated one
mv "$temp_file" "$file"
echo "Updated $file"
}
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "Error: jq is not installed. Please install jq to run this script."
exit 1
fi
# Check if a directory was provided
if [ $# -eq 0 ]; then
echo "Error: No directory specified"
echo "Usage: $0 <directory>"
exit 1
fi
DASHBOARDS_DIR="$1"
# Check if the provided directory exists
if [ ! -d "$DASHBOARDS_DIR" ]; then
echo "Error: Directory not found: $DASHBOARDS_DIR"
exit 1
fi
# Process all .ndjson files in the specified directory
echo "Processing .ndjson files in $DASHBOARDS_DIR"
for file in "$DASHBOARDS_DIR"/*.ndjson; do
if [[ -f "$file" ]]; then
fix_dashboard_title "$file"
fi
done
echo "All .ndjson files have been processed."