sed is a great tool for that:
# substitute ("s/")
sed -e 's/^[[:blank:]]*// # parts of lines that start ("^") with a space/tab
s/[[:blank:]]*$//' # or end ("$") with a space/tab
# with nothing (/)