Browse Source

Added dissect_url

Alois Mahdal 11 years ago
parent
commit
60eec224ea
2 changed files with 51 additions and 0 deletions
  1. 28
    0
      README.md
  2. 23
    0
      bin/dissect_url

+ 28
- 0
README.md View File

@@ -34,6 +34,34 @@ Example:
34 34
     00000008  01110010 01101100 01100100 00001010  |rld.|
35 35
     $
36 36
 
37
+### dissect\_url ###
38
+
39
+Split URLs into components and arguments.  Output is useful to see more easily
40
+what is or is not in the URL and/or compare URls using standard tools like diff.
41
+
42
+    $ dissect_url "proto://srv:port/a/query?par1=foo&par2=bar#joe&mary"
43
+    proto://srv:port
44
+        /a/query
45
+        ?
46
+            par1=foo&
47
+            par2=bar
48
+        #
49
+            joe
50
+
51
+Note that by removing all whitespace from the dissected URL you should get the
52
+original URL.
53
+
54
+To enter multiple URLs, simply omit the argument; script will go into filter
55
+mode, where you can enter URLs one per line.  Quit this mode by entering *EOF*
56
+(`Ctrl+D`) or an empty line.  From this mode, output will be separated like this:
57
+
58
+    $ dissect_url < two_urls
59
+    === url 01 =============================================
60
+    url1
61
+
62
+    === url 02 =============================================
63
+    url2
64
+
37 65
 
38 66
 ### mkexec.pl ###
39 67
 

+ 23
- 0
bin/dissect_url View File

@@ -0,0 +1,23 @@
1
+#!/bin/bash
2
+
3
+dissect() {
4
+    echo $* | perl -pe '
5
+        s|(\w)(/[^/])|$1\n    $2|;
6
+        s|\?|\n    ?\n        |;
7
+        s|#|\n    #\n        |;
8
+        s|&|&\n        |g;'
9
+    echo ""
10
+}
11
+
12
+if [[ -n "$1" ]]; then
13
+    dissect "$1"
14
+else
15
+    i=0
16
+    while read url;
17
+    do
18
+        if [[ -z "$url" ]]; then exit 0; fi
19
+        i=`expr $i + 1`
20
+        printf "=== url %02d =============================================\n" $i
21
+        dissect "$url"
22
+    done
23
+fi