comparing column in same file to insert one more column to tha same file
I have one need to compare specific column and gives ratio
My File
Col1 col2 col3 col4 col5 col6
a s318 14 - - -
b s319 25 b t568 15
c s320 8 c t569 12
- - - d t570 20
f s322 42 f t571 5
expected output
output
Col1 col2 col3 col4 col5 col6 ratio
a s318 14 - - - 0
b s319 25 b t568 15 1.67
c s320 8 c t569 12 0.67
- - - d t570 20 0
f s322 42 f t571 5 8.4
i used awk script to get the result but its showing awk:
(FILENAME=file.txt FNR=4) fatal: division by zero attempted
awk 'NR==1{$7="ratio"}NR>1{if($3!=$6)print $7=($3)/($6)}{print}' file.txt
i need help to solve this?
No comments:
Post a Comment