Getting input data from 2 tables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting input data from 2 tables
# 1  
Old 04-23-2012
Getting input data from 2 tables

Hello All,

I have one table contains:

Table1:

5
10
30
40
60
80
...

Table 2:

10
20
60
80
120
160
..

Now I have divind table2.col 1/table1.col 1 and put the output in third table.

Can you help me to write this in awk as well as in perl....?

Thanks
Krsnadasa
# 2  
Old 04-23-2012
Hi

Hoping you do not mean to say a database table when you say "table":

Code:
$ awk 'NR==FNR{a[i++]=$0;next}{print $0/a[j++]}' file1 file2


Guru.
# 3  
Old 04-23-2012
getting input data from 2 tables

Hu Guru,

Thanks

Can you please explain me the code how it works? You are right these are not db tables.

Thanks
Krsnadasa.
# 4  
Old 04-23-2012
First, we read the contents of File1(NR==FNR) and store in an array(a[i++]=$0). Then, for every entry in the second file, we divide the number by the corresponding array value and print it(print $0/a[j++]).

Guru.
# 5  
Old 04-23-2012
Alternatively:
Code:
awk 'getline p<f {print $1/p}' f=file1 file2

This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 04-24-2012
getting input data from 2 tables

Hi Scruit,

Thanks,

I am getting correct out put but code is little difficult for me to understand. Can you please explain once?

Thanks
Krsnadasa.
# 7  
Old 04-24-2012
Sure:
Code:
awk '                  # For every line in file2
  getline p<f {        # if reading the next line from the file in variable f (containing the name of file1) into variable p is successful
    print $1/p         # then print field 1 of file2 divided by p
  }
' f=file1 file2        # set variable f to file1 and specify file2 as the input file

This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search last column of INPUT.txt in TABLEs text and add correspond columns to INPUT.txt

Hi dears i use bash shell i have INPUT.txt like this number of columns different in one some row have 12 , some 11 columns see last column INPUT.txt CodeGender Age Grade Dialect Session Sentence Start End Length Phonemic Phonetic 63 M 27 BS/BA TEHRANI 3 4 298320 310050... (2 Replies)
Discussion started by: alii
2 Replies

2. Shell Programming and Scripting

Script writing for tables with binary data

Hi There, I'm trying to write a simple script that will email me when we have an application job in a certain status that needs human intervention. I've used this script for other tables and it works great. However, this one gives me the warning that there is binary data so it might not. ... (2 Replies)
Discussion started by: Colel2
2 Replies

3. Shell Programming and Scripting

Append data by looking up 2 tables for multiple files

I want to lookup values from two different tables based on common columns and append. The trick is the column to be looked up is not fixed and varies , so it has to be detected from the header. How can I achieve this at once, for multiple data files, but lookup tables fixed. The two lookup... (5 Replies)
Discussion started by: ritakadm
5 Replies

4. Shell Programming and Scripting

Extracting data from tables......

HOw to extracts data from tables in database. Merges them into one output file. This output file is loaded into another tables in database. (1 Reply)
Discussion started by: nari.bommi
1 Replies

5. AIX

Extract data from DB2 tables and FTP it to outside company's firewall

Please help me in creating the script in AIX. requirement is; The new component's main function is to extract the data from DB2 tables and company's firewall directly. The component function needs to check the timestamp in the DB2 tables ((CREDAT and CRETIM) with the requested timestamp and... (1 Reply)
Discussion started by: priyanka3006
1 Replies

6. Shell Programming and Scripting

Shell script for comparing data of tables

Hi, I have two databases with same tables on different servers.I need to check the data content in each table and if something is missing, should print that. I have a tool which takes the snapshot the table structure,index so on and compares with the other server tables snapshot. Now i need... (1 Reply)
Discussion started by: nessj
1 Replies

7. UNIX Desktop Questions & Answers

Extracting data from tables and storing in a file

Hi I am trying to write a script to extract information from a database and save that info to a csv file. I am using sql, an oracle database I have no idea how to even begin this. Can somebody please help. (8 Replies)
Discussion started by: ladyAnne
8 Replies

8. Shell Programming and Scripting

Reading data from multiple tables from Oracle DB

Hi , I want to read the data from 9 tables in oracle DB into 9 different files in the same connection instance (session). I am able to get data from one table to one file with below code : X=`sqlplus -s user/pwd@DB <<eof select col1 from table1; EXIT; eof` echo $X>myfile Can anyone... (2 Replies)
Discussion started by: net
2 Replies

9. UNIX for Dummies Questions & Answers

extract data from html tables

hi i need to use unix to extract data from several rows of a table coded in html. I know that rows within a table have the tags <tr> </tr> and so i thought that my first step should be to to delete all of the other html code which is not contained within these tags. i could then use this method... (8 Replies)
Discussion started by: Streetrcr
8 Replies

10. Shell Programming and Scripting

Converting tables of row data into columns of tables

I am trying to transpose tables listed in the format into format. Any help would be greatly appreciated. Input: test_data_1 1 2 90% 4 3 91% 5 4 90% 6 5 90% 9 6 90% test_data_2 3 5 92% 5 4 92% 7 3 93% 9 2 92% 1 1 92% ... Output:... (7 Replies)
Discussion started by: justthisguy
7 Replies
Login or Register to Ask a Question