#parse-url #host-port #url-scheme #networking #command-line #command-line-tool #path

app rexturl

A simple tool to split urls in their protocol, host, port, path and query parts

9 releases

0.3.2 Sep 18, 2024
0.3.1 Sep 17, 2024
0.3.0 Apr 25, 2024
0.2.2 Sep 19, 2022
0.1.2 Sep 17, 2022

#186 in Command line utilities

Download history 318/week @ 2024-09-16 17/week @ 2024-09-23 30/week @ 2024-09-30 5/week @ 2024-10-07

68 downloads per month

MIT license

11KB
156 lines

rexturl

A versatile command-line tool for parsing and manipulating URLs.

Features

  • Extract specific URL components (scheme, username, host, port, path, query, fragment)
  • Custom output formatting
  • JSON output support
  • Sorting and deduplication of results
  • Process multiple URLs from command line or stdin

Installation

cargo install rexturl

or clone the repository and build from source:

git clone https://github.com/vschwaberow/rexturl.git
cd rexturl
cargo build --release

Usage

rexturl [OPTIONS] [URLS...]

If no URLs are provided, rexturl will read from stdin.

Options

--urls <URLS> Input URLs to process --scheme Extract and display the URL scheme --username Extract and display the username from the URL --host Extract and display the hostname --port Extract and display the port number --path Extract and display the URL path --query Extract and display the query string --fragment Extract and display the URL fragment --sort Sort the output --unique Remove duplicate entries from the output --json Output results in JSON format --all Display all URL components --custom Enable custom output mode --domain Extract the domain --format <FORMAT> Custom output format (default: "{scheme}://{host}{path}") -h, --help Print help information -V, --version Print version information

Examples

  1. Extract all components from a single URL:

    rexturl --all https://user:pass@example.com:8080/path?query=value#fragment
    
  2. Extract host and port from multiple URLs:

    rexturl --host --port https://example.com https://api.example.com:8443
    
  3. Process URLs from a file, extracting paths and sorting results:

    cat urls.txt | rexturl --path --sort
    
  4. Use custom output format:

    rexturl --custom --format "{scheme}://{host}:{port}{path}" https://example.com:8080/api
    
  5. Output results in JSON format:

    rexturl --json --all https://example.com https://api.example.com
    
  6. Sort and deduplicate results:

    echo -e "https://example.com\nhttps://example.com\nhttps://api.example.com" | rexturl --host --sort --unique
    

Custom Output Format

When using --custom and --format, you can use the following placeholders:

  • {scheme}
  • {username}
  • {host}
  • {domain}
  • {port}
  • {path}
  • {query}
  • {fragment}

Example:

rexturl --custom --format "Host: {host}, Path: {path}" 
https://example.com/api

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Dependencies

~2.2–3.5MB
~71K SLoC