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
gawk
echo "http://login:password@example.com/one/more/dir/file.exe?a=sth&b=sth" | awk -F"/" ' { $1=$2=$3="" gsub(/\?.*/,"",$NF) print substr($0,3) }' OFS="/"
output
# ./test.sh /one/more/dir/file.exe