Your current command will remove all instances of $up
anywhere, including multiple occurrences in a line and occurrences in the middle of a line.
If you want to match only $up
at the very beginning of a line, and only when it is a whole (whitespace-delimited) word, try the following command:
sed "s/^$up\>//"
In GNU sed, the assertion ^
matches to the beginning of a line, and \>
matches the end of a word (the zero-width "character" between a non-whitespace character and whitespace character).
If there might be whitespace before $up
, you can use
sed "s/\(\s*\)$up\>/\1/"
This will remove just the $up
and preserve all whitespace.
If you don't want to keep the whitespace between $up
and the text after it, you can replace \>
with \s\+
, which matches to one or more (\+
) whitespace characters (\s
); i.e.,
sed "s/^$up\s\+//"
sed "s/\(\s*\)$up\s\+/\1/"