I tried to use $i and $j for operation such that q=$i+$j; however, it gives me error.
Besides, I tried to grep again this "char" in another file using grep -n char$ file2 but it doesnt work. (In a typical example : grep -n element$ filename should give us the exact line of element)
I have error in echo where it doesnt allow me to perform computation. I am thinking to use AWK whihc is put easier but I could not because it invovles multiple files to read and compare.
Please advise what is the best solution for this. Thanks!
Does it means bc will round down the value? How can I get the exact value of division in this case?
ii) As I raised before, given the file has quite similar number.It will still print out all the possible number that found.
++ awk '{print $1}'
+ k='2:
3:'
This basically print the positions of file in c.txt(below) when 108 is grepped. Which means k=`grep -n "$char" c.txt|awk '{print $1}'` is not working to grab exact number.
iii)the (standard_in) 1: parse error comes in when the bc tries to calculate non value from (non match entry). Do you have any idea how to prevent the q to be calculate when the grep returns empty?
I tried to insert while and if inside but it returns me
./grep2.bash: line 49: syntax error near unexpected token `done'
./grep2.bash: line 49: `done '
select b.col2 i, b.col3 j, c.col1 k, (b.col3/b.col2)+b.col3 q
from a.txt a, b.txt b, c.txt c
where a.col2 = b.col1
and a.col2 = c.col3
See how simple & clean? Now you just need to upload these three files into three database tables
On a serious note, use FILENAME variable in awk to differentiate between multiple files. Using awk is much better than wrestling with shell constructs/commands - particularly if your files are big. The performance gains are massive.
I tried before on scaling method and i do not know how to turnaround especially in my scenario.
Thanks. I managed to use rikxik formula and it is working. The reason is because i am actually parsing the whole echo to a variable rather than echo alone.
However, on the other note, I still havent resolve the grep problem where it still return me any value which is matching the number rather than exact number (grep -n number$ filename).Still finding what character I missed out to isolate the "$" so that the number is uniquely grabbed from the file.