I have a file that contains the something like this
a=15
b=21.5
c=544
and so on
the question is how could I find the line that contains the value of c and store its value on a variable in bash shell?, Thanks in advanced
I have a file that contains the something like this
a=15
b=21.5
c=544
and so on
the question is how could I find the line that contains the value of c and store its value on a variable in bash shell?, Thanks in advanced
If c is prsent in the file. It will be good to test first if c is present ( use grep with option c to get the count and compare it with 0)
var = `grep c filename | grep -v grep | cut -d "=" -f2`
cheers,
Devaraj Takhellambam
More possibilties:
var=$(awk -F= '/c=/{print $2}' file)
var=$(sed -n 's/c=//p' file)
Thanks for the answer, I've tested the first one and it works, thanks a lot, but for the real case I'm working with does not (the first message file composition was an example that I thought was equivalent). The real line and value that I'm looking for has the following composition
Total Transmitted pow. 0.984574121
and cut -d does not accept two spaces as delimiter between the string to remove and the value to store. The point causes also some conflicts with the point after pow. I'm on testing the second
Got it!, I had not understood the delimiters politics properly,
var=` grep "Total Transmission pow." file.dat | cut -d "." -f2,3`
thanks again!