Thursday, 25 April 2013

Unix Shell Script : Removing Leading and Trailing spaces from a string

Leading spaces from value of a variable can be removed as follows:

$ echo $var | sed 's/^ *//g'

Trailing spaces from value of a variable can be removed as follows:

$ echo $var | sed 's/ *$//g'

No comments:

Post a Comment