combine 3 files by grouping


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting combine 3 files by grouping
# 1  
Old 04-22-2011
combine 3 files by grouping

I have a file, which is really large but i shortened it:

Code:
A3059GVS        1       A       01      Plate_1 40      25.37016        14.6298
A3059GVS        2       A       01      Plate_2 40      26.642002       13.3583
A3059GVS        3       A       02      Plate_1 40      25.381462       14.6185
A3059GVS        4       A       02      Plate_2 40      26.452559       13.5474
A3059GVS        5       A       03      Plate_1 40      25.547625       14.4524
A3059GVS        6       A       03      Plate_2 40      26.368746       13.6313
A3059GVS        7       A       04      Plate_3 40      24.91846        15.0815
A3059GVS        8       A       04      Plate_4 40      26.162086       13.8373
A3059GVS        9       A       05      Plate_3 40      24.230042       15.7722
A3059GVS        10      A       05      Plate_4 40      25.976826       14.0232
....
....
A3059GVT        1       A       01      Plate_1 40      25.37016        14.6298
A3059GVT        2       A       01      Plate_2 40      26.642002       13.3582
A3059GVT        3       A       02      Plate_1 40      25.381462       14.6185
A3059GVT        4       A       02      Plate_2 40      26.452559       13.5474
A3059GVT        5       A       03      Plate_1 40      25.547625       14.4524
A3059GVT        6       A       03      Plate_2 40      26.368746       13.6311
A3059GVT        7       A       04      Plate_3 40      24.91846        15.0815
A3059GVT        8       A       04      Plate_4 40      26.162086       13.8379
A3059GVT        9       A       05      Plate_3 40      24.230042       15.7732
A3059GVT        10      A       05      Plate_4 40      25.976826       14.0232
....
....
A3059GVU        1       A       01      Plate_1 40      25.37016        14.6298
A3059GVU        2       A       01      Plate_2 40      26.642002       13.3581
A3059GVU        3       A       02      Plate_1 40      25.381462       14.6185
A3059GVU        4       A       02      Plate_2 40      26.452559       13.5478
A3059GVU        5       A       03      Plate_1 40      25.547625       14.4524
A3059GVU        6       A       03      Plate_2 40      26.368746       13.6316
A3059GVU        7       A       04      Plate_3 40      24.91846        15.0815
A3059GVU        8       A       04      Plate_4 40      26.162086       13.8379
A3059GVU        9       A       05      Plate_3 40      24.230042       15.7702
A3059GVU        10      A       05      Plate_4 40      25.976826       14.0232

The first column is an ID for 3 seperate grouping of 4 "Plate_1-4"
i need to append two more columns from two seperate files:
med.txt
Code:
Plate_1 14.29425
Plate_2 13.787
Plate_3 13.13745
Plate_4 16.64165
Plate_1 12.00325
Plate_2 17.2352
Plate_3 12.7458
Plate_4 17.16795
Plate_1 13.2605
Plate_2 17.2394
Plate_3 5.20885
Plate_4 9.649275

dev.txt
Code:
Plate_1 2.513278
Plate_2 0.5764198
Plate_3 0.4848839
Plate_4 0.8792527
Plate_1 1.781646
Plate_2 0.5698595
Plate_3 0.4665879
Plate_4 0.5185251
Plate_1 0.5510285
Plate_2 1.800977
Plate_3 5.690574
Plate_4 6.47827

the two new files are grouped 1-4 associated with A3059GVS-U

what is the best approach to append two more columns in respect to the first column.
# 2  
Old 04-22-2011
Quote:
Originally Posted by mykey242
the two new files are grouped 1-4 associated with A3059GVS-U
I don't see that in your example data... Is it just not shown, or is the -U inferred from something?

working on an awk something..

---------- Post updated at 01:41 PM ---------- Previous update was at 01:37 PM ----------

Code:
awk -v ROW="A3059GVS-U" '
BEGIN {
        while (getline <"col1file") COLA[$1]=$2
        while (getline <"col2file") COLB[$1]=$2
        }

{       if($1 == ROW)
                $0=sprintf("%s %s %s", $0, COLA[$1], COLB[$1]);
} 1' datafile > newfile

# 3  
Old 04-22-2011
med.txt and dev.txt have two coulmns. Plate_1 to Plate_4 three times. Reason is the first big file at the first column has only three values:
A3059GVS, A3059GVT, A3059GVU
# 4  
Old 04-22-2011
How's it supposed to tell which things you want added to what columns when neither the name nor the order has anything to do with it?
# 5  
Old 04-22-2011
i hit enter too soon. the two small files both have column two, i want to append to the original file associated with. example:
Plate_1 xxxxx and A30590GVS
Plate_2 xxxxx and A30590GVS
Plate_3 xxxxx and A30590GVS
Plate_4 xxxxx and A30590GVS

Plate_1 xxxxx and A30590GVT
Plate_2 xxxxx and A30590GVT
Plate_3 xxxxx and A30590GVT

and so on

---------- Post updated at 04:54 PM ---------- Previous update was at 04:31 PM ----------

darn forgot to intially mention for the main file column 1 and 5 are the important arrangments which reflect med.txt and dev.txt
the second column of the two smaller files need to be aligned with column 1 and 5 for the new output.
med.txt and dev.txt are calculations from the main file.

---------- Post updated at 05:33 PM ---------- Previous update was at 04:54 PM ----------

i am looking into a different approach by changing the output on med.txt and dev.txt which will associate it with the first column of the original file.
Apologies in advance for not starting off clear.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Automate splitting of files , scp files as each split completes and combine files on target server

i use the split command to split a one terabyte backup file into 10 chunks of 100 GB each. The files are split one after the other. While the files is being split, I will like to scp the files one after the other as soon as the previous one completes, from server A to Server B. Then on server B ,... (2 Replies)
Discussion started by: malaika
2 Replies

2. Shell Programming and Scripting

Grouping files on pattern

I have this Requirement where i have to group the files, I have a folder say "temp" where many files resides...files are like this; 010020001_S-ABC-Sort-DEFAW_YYYYMMDD_HHMMSS.txt 010020004_S-PQR-Sort-DRTON_YYYYMMDD_HHMMSS.txt 010020009_S-JKL-Sort_MNOLO_YYYYMMDD_HHMMSS.txt... (8 Replies)
Discussion started by: gnnsprapa
8 Replies

3. Shell Programming and Scripting

grouping log files based on counter

I have my log file as below 00:18:02 - Nothing normal; Garbage Collection kicked off & running from last 3 min... 00:19:02 - Nothing normal; Garbage Collection kicked off & running from last 4 min... 00:19:02 - Nothing normal; Garbage Collection kicked off & running from last 4 min...... (11 Replies)
Discussion started by: manas_ranjan
11 Replies

4. Shell Programming and Scripting

Combine 2 files

How to cilnd desided output from file1 and file2 with awk. file1 1 2 7 8 9 14 15 16 21 22 23 28 29 30 file2 aa bb cc dd ee ff gg hh ii jj kk ll (3 Replies)
Discussion started by: theshashi
3 Replies

5. Shell Programming and Scripting

Grouping files according to certain fields in their name

I have a list of fils stored insortedLst, and want to select certain fields to group specific files together: Example of the files would be as below: n02-z30-dsr65-ndelt0.25-varp0.002-16x12drw-run1.log n02-z30-dsr65-ndelt0.25-varp0.002-16x12drw-run2.log... (2 Replies)
Discussion started by: kristinu
2 Replies

6. Shell Programming and Scripting

combine multiple files by column into one files already sorted!

I have multiple files; each file contains a certain data in a column view simply i want to combine all those files into one file in columns example file1: a b c d file 2: 1 2 3 4 file 3: G (4 Replies)
Discussion started by: ahmedamro
4 Replies

7. Shell Programming and Scripting

parsing file names and then grouping similar files

Hello Friends, I have .tar files which exists under different directories after the below code is run: find . -name "*" -type f -print | grep .tar > tmp.txt cat tmp.txt ./dir1/subdir1/subdir2/database-db1_28112009.tar ./dir2/subdir3/database-db2_28112009.tar... (2 Replies)
Discussion started by: EAGL€
2 Replies

8. Shell Programming and Scripting

Grouping files into tars

Hi all, I have a problem where i have several files in a directory which I SCP from a server to my local machine and i would like to periodically tar/gzip them based on their naming convention. Here is the scenario: I SCP files (which all end with the same ending) periodically across to a... (3 Replies)
Discussion started by: muay_tb
3 Replies

9. Shell Programming and Scripting

Combine files with same name

I need a script that combines files with the same name. These files are on a windows directory but the PC has Cygwin so i have a limited unix command set. What I've got; WebData_9_2007-09-20.txt WebData_9_2007-09-20.txt WebData_9_2007-09-21.txt WebData_9_2007-09-20.txt... (4 Replies)
Discussion started by: jmwhitford
4 Replies

10. Shell Programming and Scripting

Need To Combine 2 Files

I have 2 files that I need to combine. One file is looks like this: 71664107;1;1;05-FEB-07;12-FEB-07; The other file looks like this: U;71664107;dummy;Pirovano;M;04-SEP-75;Georgia;MI;1;1;31;S;S;;;Y;05-02-2007;0;12-FEB-07; I need to combine both files together. I need the shorter... (4 Replies)
Discussion started by: goodmis
4 Replies
Login or Register to Ask a Question