Get string after character

StringBashExtract

String Problem Overview


I have a string that looks like this:

 GenFiltEff=7.092200e-01

Using bash, I would like to just get the number after the = character. Is there a way to do this?

String Solutions


Solution 1 - String

Use parameter expansion, if the value is already stored in a variable.

$ str="GenFiltEff=7.092200e-01"
$ value=${str#*=}

Or use read

$ IFS="=" read name value <<< "GenFiltEff=7.092200e-01"

Either way,

$ echo $value
7.092200e-01

Solution 2 - String

For the text after the first = and before the next =

cut -d "=" -f2 <<< "$your_str"

or

sed -e 's#.*=\(\)#\1#' <<< "$your_str"

For all text after the first = regardless of if there are multiple =

cut -d "=" -f2- <<< "$your_str"

Solution 3 - String

echo "GenFiltEff=7.092200e-01" | cut -d "=" -f2 

Solution 4 - String

This should work:

your_str='GenFiltEff=7.092200e-01'
echo $your_str | cut -d "=" -f2

Solution 5 - String

${word:$(expr index "$word" "="):1}

that gets the 7. Assuming you mean the entire rest of the string, just leave off the :1.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser788171View Question on Stackoverflow
Solution 1 - StringchepnerView Answer on Stackoverflow
Solution 2 - StringTuxdudeView Answer on Stackoverflow
Solution 3 - StringGreg GuidaView Answer on Stackoverflow
Solution 4 - StringjmanView Answer on Stackoverflow
Solution 5 - StringExplosion PillsView Answer on Stackoverflow