In my bash script I need to extract just the path from the given URL. For example, from the variable containing string:
http://login:password@example.com/one/more/dir/fi
If you have a gawk:
$ echo 'http://login:password@example.com/one/more/dir/file.exe?a=sth&b=sth' | \
gawk '$0=gensub(/http:\/\/[^/]+(\/[^?]+)\?.*/,"\\1",1)'
or
$ echo 'http://login:password@example.com/one/more/dir/file.exe?a=sth&b=sth' | \
gawk -F'(http://[^/]+|?)' '$0=$2'
Gnu awk can use regular expression as field separators(FS).