Created
          September 22, 2025 11:38 
        
      - 
      
- 
        Save martinhj/0c4eff7437c7e6250239cfc026a452fa to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/usr/bin/env bash | |
| # Usage: ./find-link.sh https://example.com/sitemap.xml "/kategori/tittel" | |
| SITEMAP_URL="$1" | |
| SEARCH_STRING="$2" | |
| if [ -z "$SITEMAP_URL" ] || [ -z "$SEARCH_STRING" ]; then | |
| echo "Usage: $0 <sitemap_url> <search_string>" | |
| exit 1 | |
| fi | |
| # Download and extract URLs from sitemap using sed (BSD-compatible) | |
| urls=$(curl -s "$SITEMAP_URL" | sed -n 's:.*<loc>\(.*\)</loc>.*:\1:p') | |
| for url in $urls; do | |
| # Fetch HTML content | |
| html=$(curl -s "$url") | |
| # Look for exact match of string followed by delimiter (quote, space, >, /, or end of line) | |
| if echo "$html" | egrep -q "$SEARCH_STRING([\"' >/]|$)"; then | |
| echo "---- Found in $url ----" | |
| # Print matching lines with line numbers | |
| echo "$html" | egrep -n "$SEARCH_STRING([\"' >/]|$)" | |
| echo | |
| fi | |
| done | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment