canecse canecse - 1 year ago 155
Bash Question

How to cut a string after a specific character in unix

So I have this string:


I just want to extract the directory address meaning I only want the bit after the ":" character and get:



I need a generic command so the cut command wont work as the $var variable doesn't have a fixed length.

Answer Source

Using sed:

$ var=server@
$ echo $var | sed 's/.*://'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download