shell command using sed editor
echo http://www.domain.com/?params | sed -e 's;https\?://;;' | sed -e 's;/.*$;;'
output www.domain.com
How can i use the unix awk editor to output this string?
awk {print} ?
shell command using sed editor
echo http://www.domain.com/?params | sed -e 's;https\?://;;' | sed -e 's;/.*$;;'
output www.domain.com
How can i use the unix awk editor to output this string?
awk {print} ?
You could try this,
$ echo http://www.domain.com/?params | awk -F/ '{print $3}'
www.domain.com
Through grep,
$ echo http://www.domain.com/?params | grep -oP '(?<=/)[^/]+(?=/)'
www.domain.com
Through sed,
$ echo http://www.domain.com/?params | sed 's/.*\/\([^\/]\+\)\/.*/\1/'
www.domain.com
With awk and gsub:
$ echo http://www.domain.com/?params | awk '{gsub("\\/\\?params$", ""); print}'
http://www.domain.com
$ echo http://www.domain.com/?params | awk '{gsub("\\/\\?params$",""); gsub("^http://",""); print}'
www.domain.com
Or, (thanks Avinash Raj):
$ echo http://www.domain.com/?params | awk '{gsub(/\/\?params$|^http:\/\//,""); print }'
www.domain.com
Perl:
$ echo http://www.domain.com/?params | perl -pe 's/^http:\/\/([^\/]+).*/\1/'
www.domain.com
Or:
$ echo http://www.domain.com/?params | perl -ne 'print "$1\n" if /^http:\/\/([^\/]+)/; '
www.domain.com
$ echo http://www.domain.com/?params | awk '{gsub(/\/\?params|http:\/\//,"")}1'Mix it up a bit
expr match http://www.domain.com/?params '.*/\(.*\)/'
or
expr http://www.domain.com/?params : '.*/\(.*\)/'
Incase there are more slashes later on
expr http://www.domain.com/?params/ : '.*//\([^/]*\)/'
Incase something really wierd is going on with the slashes
expr http://www.domain.com/?params/ : '[^/]*//\([^/]*\)/'