I have a variable which has content like
----- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ----------------------------------|---------|----------|---------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- All files | 36.95 | 20.87 | 24.
PS: The output I mentioned is actually pretty long and I trimmed it for the sake of posting here. I found out by trial and error that All files <> | was between position 970-990
I am trying to extract the value associated with All files i.e 36.95. I am able to use cut to get the substring like this
TOTAL="$(cut -c 975-990 <<< $RES)"
But I am looking for better approach for example using a regex pattern, I saw patterns like grep and awk but I am not able to formulate it.
cut -c 499-504). What does it mean for a value to be "associated with All files"? Do you mean the|-delimited field following it?$RESunquoted in your question I suspect you're using it unquoted to show it's contents in your question,echo $RES, and it in fact DOES contain newlines but by not quoting the variable you're stripping them, Please edit your question to show the output ofecho "$RES"(i.e. with quotes to retain the original content).