...
...
I am using the following command to get the sum and it is working correctly but I am getting syntax error as well.
(Tried with bc -l as well)
Syntax error received for every line numbers.
(standard_in) 3: syntax error
...
While I agree with vgersh99 that you don't need bc when you are using awk anyway (since awk can perform the summation itself), I was curious to know what exactly is causing the error.
Looks like you are generating a bunch of "bc" commands that you pipe into bc.
With a sample file that has floating point numbers in it, I tried your code in my system that consists of Cygwin 1.6.10, GNU bash 3.2.39, GNU awk 3.1.6, GNU bc 1.06.
And inside a shell script, the logic works well:
So it looks like there is something wrong with the data in that "temp.hash.txt" file.
Apparently, "bc" balks at line number 3:
which would be the line in red below:
So if I change the 2nd line of "temp.hash.txt", I am able to reproduce your error:
In the shell script as well:
So I'd guess that maybe line # 2 of your temp.hash.txt does not have an integer or float(?)
Thanks everyone for the reply. durden_tyler 's comments helped me. Thanks.
The issue was in the temp.hash.txt, we encountered null values and the sum was not getting computed and resulted in parsing error. The comment from "durden_tyler" was on the same note about the way he reproduced the error by placing a character instead of number and that resulted in syntax error.
Now to the point why I did not use the command
This is important for everyone to know why I had to go this route. Actually I was using the above command earlier.
The issue for the above command rises from the difference between float and decimal.
The problem with float number addition is once it goes beyond or less than a significant number, it refers arithmetic log values. You may have noticed this in excel as well when you get numbers in the format of “78768898E+11” or “676767E-4” (an example which you can find in excel).
I never got any number with E+xxxx or E-xxxx like in excel however I was getting random numbers in 3rd and 4th decimal places because I have a huge file with only 2 decimal point numbers.
You can understand with 2 decimal places numbers, it can never have 3rd and 4th decimal place numbers but with usage of
-- I was getting such result and there was a reconciliation issue with a database decimal value.
Last edited by Scrutinizer; 07-18-2017 at 11:31 PM..
Reason: code tags
awk -F, ' NR>1 {
BEGIN{
chr=$2
}
END{
for (k in chr) {print k}
}
} ' $gene_file
I've a really simple code. I want to store gene name and it's chromosome and in the end print them.
I'm skipping line one as it contains headers.
But I don't know why I get error as: (2 Replies)
Can anyone work out why this line has a syntax error?
awk '{if ($1==1) print NR,$0 } '${PROJECT}/${data_dir}/${ofolder}/STDEV/otimes_${per}_secs.dat > tmp2.txt
I've check that the file exists in the given location (1 Reply)
Hi All,
I wrote a simple script.sh program
for i in seq (22)
do awk '$1==${i}' file1.txt|awk '{print $2}'> file${i}_study.txt
done
and then run it
%bash
%chmod +x script.sh
% ./script.sh
Give me error
awk: $1==${i}
awk: ^ syntax error
Do you have any idea why... (3 Replies)
I have a file called test.dat which contains
a b
I have written a shell script called test.sh
for i in `cat test.dat`
do
echo $i
done
When i run this script using
sh test.sh
I get this message -
test.sh: syntax error at line 6: `end of file' unexpected
What is the... (3 Replies)
hi there
i write one awk script file in shell programing
the code is related to dd/mm/yy to month, day year format
but i get an error
please can anybody help me out in this problem ??????
i give my code here including error
awk `
# date-month -- convert mm/dd/yy to month day,... (2 Replies)
I generate a fullpath variable two different ways:
1) concat two variables rootpath and relpath to give me fullpath
2) use 'find' to get the fullpath
when I echo the variable, I get the same output for both. However,
I print the variable from method 1 in the below loop I get "awk syntax... (0 Replies)
Due to some syntax error, my below code is not working.
#!/usr/bin/ksh
nawk '
BEGIN {
cur_val=0; cur_zero=0; cur_nine=0;
sum_zero=0; sum_nine=0;
}
/^/ {
cur_val=substr($0,5,2);
if("cur_val" == "0")
{
... (3 Replies)