You are, in your regular expression, trying to match a
/ after the string
/ is not there in the input, so the expression does not match.
Modified to include the
/ in the input:
$ echo /home/tolstoy/ | sed 's;\(/home\)/tolstoy/;\1/lt/;'
Modified to not match a trailing
$ echo /home/tolstoy | sed 's;\(/home\)/tolstoy;\1/lt/;'
Modified to properly find the parent directory of
tolstoy (regardless of trailing
/ in the input) and to add
lt to the end of that path:
$ printf '%s/lt\n' "$(dirname /home/tolstoy)"
$ printf '%s\n' "$(dirname /home/tolstoy)/lt"
In general, don't use line-oriented text editing tools on Unix pathnames. Doing so would disqualify the script or command you are writing from working properly with some (albeit uncommon but valid) pathnames containing newlines.