Skip to content
TheChatArchiveThe Chat Archive
Mistralmistral-medium-2505· Mistral AIHugging Face LMArena Human Preference 140K

how do I extract all "http[s]://+/" from files in a tree, and print only those urls,…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-opus-4-20250514-thinking-16k’s answer.
  1. User

    how do I extract all "http[s]://+/" from files in a tree, and print only those urls, from cli

  2. Mistral Assistant

    To extract all http:// and https:// URLs from files in a directory tree and print only those URLs from the command line, you can use a combination of grep, find, and other Unix tools. Here's a step-by-step solution:

    Method 1: Using grep with find

    find /path/to/directory -type f -exec grep -Eo 'https?://[^[:space:]]+' {} + | sort | uniq
    

    Explanation:

    1. find /path/to/directory -type f

      • Recursively finds all files (-type f) in the specified directory.
    2. -exec grep -Eo 'https?://[^[:space:]]+' {} +

      • grep -Eo uses extended regex (-E) and prints only the matching part (-o).
      • The regex https?://[^[:space:]]+ matches:
        • http followed by an optional s (https?).
        • :// (the protocol separator).
        • [^[:space:]]+ (any sequence of non-whitespace characters after ://).
    3. sort | uniq

      • Sorts the URLs and removes duplicates (optional).

    Method 2: Using ripgrep (faster alternative)

    If you have ripgrep installed (rg), you can use:

    rg -o 'https?://[^[:space:]]+' /path/to/directory | sort | uniq
    

    Explanation:

    • rg -o searches recursively and prints only the matching part.
    • The regex is the same as above.

    Method 3: Using ack (another alternative)

    If you have ack installed:

    ack -o 'https?://[^[:space:]]+' /path/to/directory | sort | uniq
    

    Notes:

    • Replace /path/to/directory with your target directory (e.g., . for the current directory).
    • If you want to include more URL patterns (e.g., ftp://), modify the regex:
      grep -Eo '(https?|ftp)://[^[:space:]]+'
      
    • If you want to exclude certain file types (e.g., binary files), add -I to grep:
      find /path/to/directory -type f -exec grep -I -Eo 'https?://[^[:space:]]+' {} + | sort | uniq
      

    Example Output:

    http://example.com
    https://example.org/path
    https://another-site.com
    

    This will extract all HTTP/HTTPS URLs from files in the directory tree and print them.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.