I have a string like this
<user>@<server>:<port>:/foo/bar
and I would like to extract the user, server, port and directory.
The user can easily be extracted by
echo <string> | awk -F"@" '{print $1;}'
But the server lies within two different delimeters. Is this possible via awk
?
You can combine two
cut
commands to extract the server name:Explanation:
echo <string> |
use the string as inputcut -d":" -f1 |
set field delimiter to:
and extract the first field (<user>@<server>
)cut -d"@" -f2
set filed delimiter to@
and extract the secon field (<server>
)Yes it is possible - using a regular expression for the delimiter
or
How about grep only,