0

This question already has an answer here:

I'm trying to parse out test ids from a source file with grep, then concatenate all the cases into a single string.

Here I declare the empty string

adrCases=""

then I loop over all lines in the source file with character pattern "// AdrCase "

grep -n "// AdrCase " ${sourceFile} | while read -r line ; do
    str=${line}
    value=${str#*"// AdrCase "}
    str=${value}
    value=${str#*" "}
    echo "adr case ID = "${value}
    adrCases=${adrCases}'"'${value}'",'
done

then echo the concatenated string

echo "adrCases = ${adrCases}"

but the string is just empty, and terminal echos

adrCases =

but ${value} echos the correct ID i.e. // AdrCase 12 53 would be have 53 parsed since there are two cases id, of which I want the latter. Parsing logic seems correct, but not string concatenation logic.

marked as duplicate by Stephen Harris, Jeff Schaller, Mr Shunz, Thomas, msp9011 Jan 21 at 12:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Browse other questions tagged or ask your own question.