Reputation: 190
I want to parse the following word in shell script
VERSION=METER1.2.1
Here i want to split it as two words as
WORD1=METER
WORD2=1.2.1
Let me help how to parse it?
Upvotes: 0
Views: 843
Reputation: 295413
Far more efficient than using external tools such is sed is bash's built-in parameter expansion support. For instance, if you want the name
variable to contain everything until the first number, and the numbers
variable to contain everything after the last alpha character:
version=METER1.2.1
name=${version%%[0-9]*}
numbers=${version##*[[:alpha:]]}
To understand this, see the BashFAQ entry on string manipulation in general, or the BashFAQ entry on parameter expansion in particular.
Upvotes: 2