awk - How to parse URL params in shell script -
i have tried same in python parse url params know if there way same in shell script.
say, have url value:
http://www.abcdsample.com/listservices?a=1&b=10&c=abcdeeff&d=1663889&listservices=a|b
required output:
url: http://www.abcdsample.com/ service: listservices a=1 b=10 c=abcdeeff d=1663889 listservices=a|b
here 1 method:
begin{ fs="?" } { url=$1 sub(/[^/]*$/,"",url) print "url:",url sub(/.*[/]/,"",$1) print "service:",$1 n=split($2,b,/&/) (i=1;i<=n;i++) print b[i] }
save script.awk
, run awk -f script.awk file
:
url: http://www.abcdsample.com/ service: listservices a=1 b=10 c=abcdeeff d=1663889 listservices=a|b
note: work url like:
- http://www.abcdsample.com/listservices?a=1&b=10&c=abcdeeff&d=1663889&listservices=a|b
- www.abcdsample.com/listservices?a=1&b=10&c=abcdeeff&d=1663889&listservices=a|b
- abcdsample.com/listservices?a=1&b=10&c=abcdeeff&d=1663889&listservices=a|b
- listservices?a=1&b=10&c=abcdeeff&d=1663889&listservices=a|b
Comments
Post a Comment