How to extract substring in Fish shell?
A possible solution is to use cut
but, that look hackish:
set location "America/New_York"
echo $location|cut -d '/' -f1
America
Since fish 2.3.0, there's a builtin called string
that has several subcommands including replace
, so you'll be able to do
string replace -r "/.*" "" -- $location
or
set location (string split "/" -- $location)[1]
See http://fishshell.com/docs/current/commands.html#string.
Alternatively, external tools like cut
, sed
or awk
all work as well.