I have a variable with, among others, a line that looks like this
iBMC=277
I'm trying to match that like this:
BMC="$(echo "$allnow" | grep iBMC=[0-9] | sed 's/iBMC=//g')"
This makes BMC empty. Here's what it looks like in bash -x
:
++ grep 'iBMC=[0-9] '
++ sed s/iBMC=//g
+ BMC=
I also have to match more things, like in this line:
Name="$(echo "$allnow" | grep stringName= | sed 's/stringName=//g')"
But it also turns out empty. Here is $allnow
:
QQ1=0999999
QQ2=00aaaaa
RR=yes
GG=no
stringName=skolan8
sTitle=
iBMC=277
L3-cache="8 MB"
Minne="16 GB"
grep 'iBM=[0-9] '
isn't the same asgrep iBMC=[0-9]
. What did you type? Also, inawk
:BMC="$(echo "$allnow" | awk -F = '/iBMC=[0-9]/{print $2}')"
– muru Dec 15 '15 at 08:47BMC="$(echo "$allnow" | sed -n 's/^iBMC=//g;T;P')"
– Mel Dec 15 '15 at 09:12$allnow
variable. For instance, if you setallnow
from the interactive shell and are trying to access it from a script, you would need to useexport
(or rethink your strategy). What doesecho "$allnow"
in the script show? – Wildcard Dec 15 '15 at 10:32allnow
set? Edit: Actually, I just looked again; @muru is right. Ifbash -x
shows you are grepping for'iBMC=[0-9] '
, then that's your problem—you have more than one digit and no space in that line. – Wildcard Dec 15 '15 at 10:39$BMC
. It looks like thisallnow="$(cat "$1" | sed '/Vars/!d' | sed 's/\&/\(newline here) /g' | sed '/STOP=/d' | sed 's/.*\<.*iBMC/iBMC/g' | awk '!a[$0]++')"
the (newline here) is a literal newline, it didn't show one in the comments here so I added that. – Dec 15 '15 at 10:44awk
rather than making a huge pipeline iterating through the file 9+ times to set your variables. Also see http://unix.stackexchange.com/q/169716/135943. But, to make it work as written, find out why you have an extra space showing in the arg togrep
; that's your immediate trouble. – Wildcard Dec 15 '15 at 10:48