Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HTML_FILE="index.html"
- # Remove specific unwanted line
- remove_unwanted_line() {
- local pattern="Video could not be embedded\."
- # Check if there are any lines matching the pattern
- if grep -q "$pattern" "$HTML_FILE"; then
- echo "Found failed posts in the file. Removing them..."
- # Remove the lines containing the pattern
- sed -i "/$pattern/d" "$HTML_FILE"
- echo "Failed posts have been removed."
- else
- echo "No failed posts found in the file."
- fi
- }
- # Function to display blog entries as a menu
- display_menu() {
- echo "Blog Entries:"
- # Extract and list blog entries with their timestamps and titles
- grep -oP "<div class='post'>.*?</div>" "$HTML_FILE" | \
- sed -E "s/<div class='post'>([^<]*).*?<h3>([^<]*)<\/h3>.*/\1 | \2/" | nl -w2 -s") "
- echo "Enter the number of the entry to delete (or 'q' to quit):"
- read -r choice
- if [[ "$choice" =~ ^[0-9]+$ ]]; then
- # Adjust the choice to properly match the `grep` output (line numbers start at 1, not 0)
- adjusted_choice=$((choice))
- # Retrieve the raw HTML block for the selected entry
- selected_entry=$(grep -oP "<div class='post'>.*?</div><div class='video-container'>.*?</div>" "$HTML_FILE" | sed -n "${adjusted_choice}p")
- if [[ -n "$selected_entry" ]]; then
- # Remove the selected block from the HTML file
- sed -i "/$(echo "$selected_entry" | sed 's/[^^]/[&]/g; s/\^/\\^/g')/d" "$HTML_FILE"
- echo "Blog entry deleted."
- else
- echo "Invalid choice. No entry found."
- fi
- elif [[ "$choice" == "q" ]]; then
- echo "Exiting."
- exit 0
- else
- echo "Invalid choice. Please try again."
- fi
- }
- # Remove the unwanted line before proceeding
- remove_unwanted_line
- # Run the menu
- display_menu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement