Trimming Whitespace From Beginning and end of Text Lines
Warren Block
wblock at wonkity.com
Fri May 12 11:38:58 PDT 2006
On Fri, 12 May 2006, Giorgos Keramidas wrote:
>> The first sed expression is missing "//". Correcting that:
>> sed -i -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' test.txt
>> sed: lstat: No such file or directory
>
> Yeah, I noticed the missing // in the first regexp, but only
> after I had posted the message. You're right, of course :)
>
> It seems odd that the fixed expression doesn't work though.
> Which version of FreeBSD is this and what sed are you running?
>
> $ uname -v
FreeBSD 4.11-STABLE #0: Wed Mar 22 19:18:33 MST 2006
> $ type sed
That's a sh-ism (normally I use csh):
sed is /usr/bin/sed
Interestingly, the problem is different on 6.1 (csh or sh):
sed -i -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' test.txt
sed: -e: No such file or directory
...which is solved by giving a blank argument for -i:
sed -i'' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' test.txt
Gah.
-Warren Block * Rapid City, South Dakota USA
More information about the freebsd-questions
mailing list