I am trying to enter a third column in this file, but the third column should that I call "Math" perform a some math calculations based on the value found in column #2.
Here is the input file:
Here is the desired output:
Output
GERk0203078$ Levir Math
Cotete_1 84412351 (Value of Levir * Constant)/ constant
Cotete_2 39308596 (Value of Levir * Constant)/ constant
Cotete_3 39393962 (Value of Levir * Constant)/ constant
GERk0203040$ Levir
Cotete_1 37235657 (Value of Levir * Constant)/ constant
Cotete_2 84227986 (Value of Levir * Constant)/ constant
Cotete_3 30187827 (Value of Levir * Constant)/ constant
GERk0203050$ Levir
Cotete_1 37217582 (Value of Levir * Constant)/ constant
Cotete_2 30317038 (Value of Levir * Constant)/ constant
Cotete_3 3010017 (Value of Levir * Constant)/ constant
I started this script but not sure how to get the value from column Levir:
#!/usr/bin/ksh
#a is the first constant
#b is the second constant
a=75
b=2500
awk 'NR<=$a {print $1, $2, ("Math" )}' addcolumn > addcolumn.xls
expr ($Levir '*$a') / $b
#!/usr/bin/ksh
echo Enter a value for p
read p
a=16384
b=1228800
c=2914
expr $c '*' $c > e
expr $a/$b > x
cat e | expr $x/$e > y
expr $p '*' $y > d
awk -v '{ print $1, $2, ($2*d); }' addcolumn > add.xls
I don't know why you kept -v when you didn't keep all the stuff it's for.
I'm having a hard time telling what you want to do with this code. I tried to show you how to move the expr into awk (where it belongs) but you've just added more of them. (Half of them with incorrect syntax that's probably throwing errors all by itself.) What're all the expr's for? What're you actually trying to do?
---------- Post updated at 09:20 AM ---------- Previous update was at 09:12 AM ----------
Did you copy paste what I gave you literally? The adaptation you tried last time needed a lot of work. Show what you actually did.
It'd also help to know what your system is.
I have no idea why it works with nawk but not awk. I tried it on the 'worst' version of awk I have available myself; as far as I know I did nothing that needed nawk.