add fix link/ref script
This commit is contained in:
parent
71c1aeb355
commit
ebc2396ce2
65
fix-link.sh
65
fix-link.sh
@ -1,51 +1,28 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Check if input file is provided
|
INPUT_FILE="$1"
|
||||||
if [ $# -ne 1 ]; then
|
|
||||||
echo "Usage: $0 <input_file>"
|
if [[ ! -f "$INPUT_FILE" ]]; then
|
||||||
|
echo "Error: Input file does not exist."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
input_file="$1"
|
while IFS=':' read -r file_path line_err status desc data; do
|
||||||
|
# Trim whitespace from variables
|
||||||
|
file_path="$(echo "$file_path" | xargs)"
|
||||||
|
line_err="$(echo "$line_err" | xargs)"
|
||||||
|
status="$(echo "$status" | xargs)"
|
||||||
|
desc="$(echo "$desc" | xargs)"
|
||||||
|
data="$(echo "$data" | xargs | tr -d "'")" # Remove quotes from data
|
||||||
|
|
||||||
# Check if file exists
|
if [[ -f "$file_path" ]]; then
|
||||||
if [ ! -f "$input_file" ]; then
|
if [[ "$desc" == "undefined label" ]]; then
|
||||||
echo "Error: File '$input_file' not found"
|
fixed_data="$(echo "$data" | tr '\\/_' '-')"
|
||||||
exit 1
|
sed -i "s@$data@$fixed_data@g" "$file_path"
|
||||||
fi
|
elif [[ "$desc" == *"toctree contains reference to nonexisting document"* ]]; then
|
||||||
|
fixed_data="$(echo "$data" | tr '\\/_' '-')"
|
||||||
# Process each line of the input file
|
sed -i "s@$data@$fixed_data@g" "$file_path"
|
||||||
while IFS= read -r line || [ -n "$line" ]; do
|
fi
|
||||||
# Skip empty lines
|
|
||||||
[ -z "$line" ] && continue
|
|
||||||
|
|
||||||
# Extract filepath (everything before first colon)
|
|
||||||
filepath=$(echo "$line" | cut -d: -f1)
|
|
||||||
|
|
||||||
# Extract status (WARNING)
|
|
||||||
status="WARNING"
|
|
||||||
|
|
||||||
# Split based on different patterns
|
|
||||||
if [[ "$line" =~ "WARNING: toctree contains reference to nonexisting document" ]]; then
|
|
||||||
description="toctree contains reference to nonexisting document"
|
|
||||||
data=$(echo "$line" | sed "s|^.*$description ||")
|
|
||||||
elif [[ "$line" =~ "WARNING: undefined label:" ]]; then
|
|
||||||
description="undefined label:"
|
|
||||||
data=$(echo "$line" | sed "s|^.*$description ||")
|
|
||||||
else
|
|
||||||
# For the first line with deprecated substitutions
|
|
||||||
description=$(echo "$line" | sed "s|^.*WARNING: ||" | sed "s| \[.*$||")
|
|
||||||
data=$(echo "$line" | grep -o "\[.*$" | tr -d '[]')
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Replace /, \, and _ with - in data
|
done < "$INPUT_FILE"
|
||||||
modified_data=$(echo "$data" | tr '/\\_' '-')
|
|
||||||
|
|
||||||
# Print the results
|
|
||||||
echo "filepath = $filepath"
|
|
||||||
echo "status = $status"
|
|
||||||
echo "description = $description"
|
|
||||||
echo "data = $modified_data"
|
|
||||||
echo "-------------------"
|
|
||||||
|
|
||||||
done < "$input_file"
|
|
||||||
|
Loading…
Reference in New Issue
Block a user