Q:

Extract number of variable length from string

I want to extract a number of variable length from a string.
The string looks like this:
used_memory:1775220696

I would like to have the 1775220696 part in a variable. There are a lot of questions about this, but I could not find a solution that suits my needs.

A:

You can use cut:
my_val=$(echo "used_memory:1775220696"  | cut -d':' -f2)

Or also awk:
my_val=$(echo "used_memory:1775220696"  | awk -F':' '{print $2}')

A:

Use parameter expansion:
string=used_memory:1775220696
num=${string#*:}              # Delete everything up to the first colon.

A:

I used to use egrep
echo used_memory:1775220696 | egrep -o [0-9]+

Output:
1775220696

