File1:
hello world
How would one delete the leading/trailing blank spaces within this file using sed - using one command (no intermediate files)?
I've currently got:
sed -e 's/^[ ]*//' a > b
For leading spaces.
sed 's/ *$//' b > c
And this for trailing spaces.
You almost got it:
sed -e 's/^[ ]*//;s/[ ]*$//' a > c
Moreover on some flavours of sed, there is also an option for editing inline:
sed
sed -i -e 's/^[ ]*//;s/[ ]*$//' a
2.1m questions
2.1m answers
60 comments
57.0k users