Advertisement
MaxDjently

remove_post-wsl.sh

Mar 27th, 2025
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.84 KB | Software | 0 0
  1. HTML_FILE="index.html"
  2.  
  3. # Remove specific unwanted line
  4. remove_unwanted_line() {
  5.     local pattern="Video could not be embedded\."
  6.  
  7.     # Check if there are any lines matching the pattern
  8.     if grep -q "$pattern" "$HTML_FILE"; then
  9.         echo "Found failed posts in the file. Removing them..."
  10.         # Remove the lines containing the pattern
  11.         sed -i "/$pattern/d" "$HTML_FILE"
  12.         echo "Failed posts have been removed."
  13.     else
  14.         echo "No failed posts found in the file."
  15.     fi
  16. }
  17.  
  18. # Function to display blog entries as a menu
  19. display_menu() {
  20.     echo "Blog Entries:"
  21.     # Extract and list blog entries with their timestamps and titles
  22.     grep -oP "<div class='post'>.*?</div>" "$HTML_FILE" | \
  23.     sed -E "s/<div class='post'>([^<]*).*?<h3>([^<]*)<\/h3>.*/\1 | \2/" | nl -w2 -s") "
  24.  
  25.     echo "Enter the number of the entry to delete (or 'q' to quit):"
  26.     read -r choice
  27.  
  28.     if [[ "$choice" =~ ^[0-9]+$ ]]; then
  29.         # Adjust the choice to properly match the `grep` output (line numbers start at 1, not 0)
  30.         adjusted_choice=$((choice))
  31.  
  32.         # Retrieve the raw HTML block for the selected entry
  33.         selected_entry=$(grep -oP "<div class='post'>.*?</div><div class='video-container'>.*?</div>" "$HTML_FILE" | sed -n "${adjusted_choice}p")
  34.  
  35.         if [[ -n "$selected_entry" ]]; then
  36.             # Remove the selected block from the HTML file
  37.             sed -i "/$(echo "$selected_entry" | sed 's/[^^]/[&]/g; s/\^/\\^/g')/d" "$HTML_FILE"
  38.             echo "Blog entry deleted."
  39.         else
  40.             echo "Invalid choice. No entry found."
  41.         fi
  42.     elif [[ "$choice" == "q" ]]; then
  43.         echo "Exiting."
  44.         exit 0
  45.     else
  46.         echo "Invalid choice. Please try again."
  47.     fi
  48. }
  49.  
  50. # Remove the unwanted line before proceeding
  51. remove_unwanted_line
  52.  
  53. # Run the menu
  54. display_menu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement