## Enter third column & Perform Operation

 Thread Tools Search this Thread
Enter third column & Perform Operation
# 1
06-10-2011
Enter third column & Perform Operation

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:

Quote:
GERk0203078\$ Levir
Cotete_1 84412351
Cotete_2 39308596
Cotete_3 39393962

GERk0203040\$ Levir
Cotete_1 37235657
Cotete_2 84227986
Cotete_3 30187827

GERk0203050\$ Levir
Cotete_1 37217582
Cotete_2 30317038
Cotete_3 30100170
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:
Any help with that would be greatly appreciated.
 Ernst View Public Profile for Ernst Find all posts by Ernst
# 2
06-10-2011
I'm assuming you want column 2 * 75 / 2100 ?

This User Gave Thanks to Corona688 For This Post:
 Corona688 View Public Profile for Corona688 Visit Corona688's homepage! Find all posts by Corona688
# 3
06-13-2011
Can someone tell me what's wrong with this code?

 Ernst View Public Profile for Ernst Find all posts by Ernst
# 4
06-13-2011
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 ----------

Quote:
Originally Posted by Ernst
Can someone tell me what's wrong with this code?

Taking your code at face value:
 Corona688 View Public Profile for Corona688 Visit Corona688's homepage! Find all posts by Corona688
# 5
06-13-2011
This is what I keep on getting when I try it.

Same issue with previous response

I even added the line below
Quote:
#!/usr/bin/ksh
but to no avail.

---------- Post updated at 11:42 AM ---------- Previous update was at 11:31 AM ----------

All I want to do is to add a 3rd column but want to use the formula to get the values for that column.

---------- Post updated at 11:46 AM ---------- Previous update was at 11:42 AM ----------

Corona, It works with nawk. I appreciate the help.
 Ernst View Public Profile for Ernst Find all posts by Ernst
# 6
06-13-2011
Quote:
Originally Posted by Ernst
This is what I keep on getting when I try it.

Same issue with previous response
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.
 Corona688 View Public Profile for Corona688 Visit Corona688's homepage! Find all posts by Corona688

## Copy last few lines of a file, perform math operation and iterate further

Hi, I am trying to generate a data of following order: 4 0 1 642 643 4 642 643 1283 1284 4 1283 1284 1924 1925 4 1924 1925 2565 2566 4 2565 2566 3206 3207 4 3206 3207 3847 3848 4 3847 3848 4488 4489 4 4488 4489 5129 5130 ---------------------- 4 1 2 643 644 4 643 644 1284...

## awk script to find data in three file and perform replace operation

Have three files. Any other approach with regards to file concatenation or splitting, etc is appreciated If column55(billngtype) of file1 contains YMNC or YPBC then pick the value of column13(documentnumber). Now find this documentnumber in column1(Billdoc) of file2 and grep the corresponding...

## Filter on one column and then perform conditional calculations on another column with a Linux script

Hi, I have a file (stats.txt) with columns like in the example below. Destination IP address, timestamp, TCP packet sequence number and packet length. destIP time seqNo packetLength 1.2.3.4 0.01 123 500 1.2.3.5 0.03 44 1500 1.3.2.5 0.08 44 1500 1.2.3.4 0.44...

## How To Perform Mathematical Operation Within If in awk?

Hi All, I am using an awk script as below: awk -F'|' 'BEGIN{OFS="|";} { if (\$1==\$3 && \$3==\$7 && \$7==\$13 && \$2==\$6 && \$6==\$11 && \$15-\$14+1==\$11) print \$0"|""TRUE"; else print \$0"|""FALSE"; }' tempfile.txt In above script, all conditions are being checked except the one which is...

## Using dbms_pipe with C++ to perform daabase operation

I am getting two result: string and int in c++ code. That I want to store into database. The request which generates result is very frequent. So each time performing db operation to store the result is costly for me. So how this can be achived using dbms_sql? I dont have any experience and how...

## Help me to perform count & group by operation in shell scripting?

Hi All, I want to display the distinct values in the file and for each distinct value how may occurance or there. Test data: test1.dat 20121105 20121105 20121105 20121105 20121106 20121106 20121106 20121105 I need to display the output like Output

## [Solved] Perform an operation to all directories

Sorry, about this thread - I solved my own problem! Thanks for taking a look. edit by bakunin: no problem, but it would have been a nice touch to actually tell us what the solution was. This would have been slightlich more educating than just knowing that you found it. I changed your title to...

## Column operation : cosne and sine operation

I have a txt file with several columns and i want to peform an operation on two columns and output it to a new txt file . file.txt 900.00000 1 1 1 500.00000 500.00000 100000.000 4 4 1.45257346E-07 899.10834 ...

## perform some operation on a specific coulmn starting from a specific line

I have a txt file having rows and coulmns, i want to perform some operation on a specific coulmn starting from a specific line. eg: 50.000000 1 1 1 1000.00000 1000.00000 50000.000 19 19 3.69797533E-07 871.66394 ...

## How to perform arithmetic operation on date

Hi all, I would appreciate if anyone knows how to perform adding to date. As for normal date, i can easily plus with any number. But when it comes to month end say for example 28 Jun, i need to perform a plus with number 3, it will not return 1 Jul. Thanks in advance for your help.