Tuesday, June 5, 2012

How to remove last 3 character of a string in Bash

The below example will: 


1.  Remove/Trim last 3 characters of a string variable.
2.  It does it in one go... 


VAR = "ap-southeast-1a"
VAR=${VAR%%???}


echo $VAR


This will output: 
ap-southeast


Simple... Isn't It?

2 comments:

  1. suppose string is 10:45:06:247 How can I replace it to 10:45:06.247. last colon changed with dot

    ReplyDelete