Search This Blog

shell scripting: remove leading and trailing character

Suppose we want to remove the leading and trail character from string: <1.2.3> and expecting result should be 1.2.3
  • Option 1:
    str=<1.2.3>
    str1="${str%\<}"
    str2="${str1#\>}"
    echo $str2
  • Option 2: Using sed
    echo "<1.2.3>" | sed -e 's/^\<//'  -e 's/\>$//'

No comments:

Post a Comment