chriscaldes09-28-2005, 11:49 AMDoes anyone know a good way to replace
a space at the end of a filename? ie: testfile.txt(space) or multiple
ending spaces?
I can do this:
echo "space file " | sed 's/\ //g'
returns: "spacefile"
but I really want to replace the LAST space..and can't figure it out.
dmacks09-28-2005, 12:13 PMYou don't usually need to backslash-protect
a space if it's in a quoted string (the shell treats "the whole quote
string as a single word).
In a sed pattern match, you can use $ to indicate "the end of the
string".
Do you need to handle more than one space at the end, or will it
always be exactly 1 space character? If the latter, you don't need the
g flag.
chriscaldes10-14-2005, 09:05 AMThis won't work - becasue of the 'g'
global flag is only going to operate on the end occurance '$'
echo "space file " | sed 's/ $//g'
this works for that though:
echo "space file " | sed 's/ *$//'