Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trim spaces

Status
Not open for further replies.

pandithiru

Programmer
Joined
Jul 17, 2004
Messages
2
Location
US
Need help to trim spaces on either side of the string.

example:
var = " UNIX is always FUN! "

I need to trim the spaces before and after the string and my variable should have the following

var="UNIX is always FUN!"

I tried the tr cmd but did not work as expected.

Thanks in advance,
pandithiru
 
Opps, that was wrong, I should real the WHOLE question before replying ! :-(
 
OK, how about
Code:
echo "      UNIX is always FUN!          " |  sed -e "s/^ *//g" -e "s/ *$//g"
 
let the shell do the job

var=" UNIX is always FUN! "
echo $var
 
Thanks, guys. Both options works fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top