Sponsored Content
Top Forums UNIX for Dummies Questions & Answers any script for joining files based on simple conditions Post 302407883 by stateperl on Friday 26th of March 2010 07:12:26 PM
Old 03-26-2010
any script for joining files based on simple conditions

Condition1;
If NPID and IndID of both input1 and input2 are same take all the vaues relevant to them and print together as output

Condition2;
IDNo in output: Take the highly repeated same letter of similar NPID-IndID as *1*
Second highly repeated same letter ...................................... as* 3*
Take different letters of .......................................... as *2*

Example (Check Bold Letters): Cond1: NPID (ID1) and IndID (a1,a2,a3,a6,a8,a9 ) of input1 similar to input2
Code:
                                                 a/a  as  1
                                                 a/b  as  2
                                                 b/b  as  3

input1

Code:
IndID    ID1    ID2    ID3
a1    a/a    b/b    c/c
a2    a/a    b/b    c/c
a3    a/b    b/b    c/d
a6    a/b    b/b    c/e
a8    a/a    b/c    c/e
a9    b/b    b/d    c/e

input2

Code:
NPID    IndID    name    Dexp    DummyID    Pop
ID1    a1    ppp    10    GI1-A    CEU
ID1    a2    ppp    20    GI1-S    CEU
ID1    a3    ppp    30    GI2-A    CEU
ID1    a4    ppp    40    GI2-S    CEU
ID1    a6    ppp    79    GI9-A    CEU
ID1    a8    ppp    62    GI7-A    CEU
ID2    a9    ppp    12    GI7-S    CEU
ID2    a1    qqq    23    GI2-A    CEU
ID2    a2    qqq    26    GI3-A    CEU
ID2    a3    qqq    28    GI3-S    CEU
ID2    a4    qqq    29    GI5-A    CEU
ID2    a6    qqq    36    GI5-S    CEU
ID2    a8    qqq    46    GI6-S    CEU
ID2    a9    qqq    22    GI6-A    CEU
ID4    a1     fff    67    GI8-A    CEU



]Desired Output
Code:
NPID    name    Column1    IDs    IDNo    Dexp    DummyID    Pop
ID1    ppp    a1    a/a    1    10    GI1-A    CEU  
ID1    ppp    a2    a/a    1    20    GI1-S    CEU
ID1    ppp    a8    a/a    1    62    GI7-A    CEU
ID1    ppp    a3    a/b    2    30    GI2-A    CEU
ID1    ppp    a6    a/b    2    79    GI9-A    CEU
ID1    ppp    a9    b/b    3    12    GI7-S    CEU 
 ID2    qqq    a1    b/b    1    23    GI2-A    CEU
ID2    qqq    a2    b/b    1    26    GI3-A    CEU
ID2    qqq    a3    b/b    1    28    GI3-S    CEU
ID2    qqq    a6    b/b    1    36    GI5-S    CEU
ID2    qqq    a8    b/c    2    46    GI6-S    CEU
ID2    qqq    a9    b/d    3    22    GI6-A    CEU

Thanx in advance

Last edited by zaxxon; 03-29-2010 at 04:04 AM.. Reason: even more code tags ;)
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Joining two files based on columns/fields

I've got two files, File1 and File2 File 1 has got combination of col1, col2 and col3 which comes on file2 as well, file2 does not get col4. Now based on col1, col2 and col3, I would like to get col4 from file1 and all the columns from file2 in a new file Any ideas? File1 ------ Col1 col2... (11 Replies)
Discussion started by: rudoraj
11 Replies

2. UNIX for Dummies Questions & Answers

Joining files based on multiple keys

I need a script (perl or awk..anything is fine) to join 3 files based on three key columns. The no of non-key columns can vary in each file. The columns are delimited by semicolon. For example, File1 Dim1;Dim2;Dim3;Fact1;Fact2;Fact3;Fact4;Fact5 ---- data delimited by semicolon --- ... (1 Reply)
Discussion started by: Sebben
1 Replies

3. Shell Programming and Scripting

joining files based on key column

Hi I have to join two files based on 1st column where 4th column of a2.txt=at and take 2nd column of a1.txt and 3rd column of a2.txt and check against source files ,if matches list those source file names. a1.txt a1|20090809|20090810 a2|20090907|20090908 a2.txt a1|d|file1.txt|at... (9 Replies)
Discussion started by: akil
9 Replies

4. Shell Programming and Scripting

awk merging files based on 2 complex conditions

1. if the 1st row IDs of input1 (ID1/ID2.....) is equal to any IDNames of input2 print all relevant values together as defined in the output. 2. A bit tricky part is IDno in the output. All we need to do is numbering same kind of letters as 1 (aa of ID1) and different letters as 2 (ab... (4 Replies)
Discussion started by: ruby_sgp
4 Replies

5. Shell Programming and Scripting

Joining multiple files based on one column with different and similar values (shell or perl)

Hi, I have nine files looking similar to file1 & file2 below. File1: 1 ABCA1 1 ABCC8 1 ABR:N 1 ACACB 1 ACAP2 1 ACOT1 1 ACSBG 1 ACTR1 1 ACTRT 1 ADAMT 1 AEN:N 1 AKAP1File2: 1 A4GAL 1 ACTBL 1 ACTL7 (4 Replies)
Discussion started by: seqbiologist
4 Replies

6. UNIX for Dummies Questions & Answers

Shell script to extract data from csv file based on certain conditions

Hi Guys, I am new to shell script.I need your help to write a shell script. I need to write a shell script to extract data from a .csv file where columns are ',' separated. The file has 5 columns having values say column 1,column 2.....column 5 as below along with their valuesm.... (1 Reply)
Discussion started by: Vivekit82
1 Replies

7. Shell Programming and Scripting

Need script for making files based on some conditions.

Hi All, I have a text file (code_data.txt) with the followig data. AMAR AB123456 XYZ KIRAN CB789 ABC RAJ CS78890 XYZ KAMESH A33535335 ABC KUMAR MD678894 MAT RITESH SR3535355... (26 Replies)
Discussion started by: ROCK_PLSQL
26 Replies

8. Shell Programming and Scripting

Merge input from two files into one based on conditions

Using Linux (bash), I have two files which contain information about berries. Example: file1.txt: Blueberry blue 14 Raspberry red 12 Blackberry dark 4 file2.txt Blackberry sour 4 3 Blueberry tasty 12 78 Strawberry yummy 33 88 I want to merge these two files into one. The desired... (5 Replies)
Discussion started by: Zooma
5 Replies

9. Shell Programming and Scripting

Trouble with simple cutting, joining

Made a file called assignment1.sh and this is what's inside - #!/bin/bash $ cut -c 2 sales.txt > regionalsales.txt $ cut -c 6 sales.txt > regionalsales.txt $ cut -c 1 territory.txt > terrsummary.txt $ cut -c 2 territory.txt > terrsummary.txt $ cut -c 3 territory.txt > terrsummary.txt $ sort... (1 Reply)
Discussion started by: htzdruk
1 Replies

10. UNIX for Beginners Questions & Answers

Rename files based on simple text file

Hello! New here although not completely new to Unix. I wonder how I could rename files based on the data found in a simple textfile. It goes like this: I have 4 files 1 ldfgkkfjslkdfjsldkfjsf.wav 2 nndsdflksdjf.wav 3 sdflksjdf jjsdflsdfl.wav 4 dkadsdddd.wav Textfile.txt looks like... (14 Replies)
Discussion started by: Oortone
14 Replies
PPPOECONF(8)						      System Manager's Manual						      PPPOECONF(8)

NAME
pppoeconf -- configures a PPPoE (ADSL) connection SYNOPSIS
pppoeconf [-nox] [iface] DESCRIPTION
The pppoeconf program is user-friendly dialog based setup tool for pppd (and pppoe if needed). It will look for existing ethernet cards and look for ADSL hardware connected to one of them. You can add an interface name iface to force pppoeconf to use it. Then it will get some login info and do some minor modifications to make working settings. Note that you can use ESC key to exit program when you wan. OPTIONS
-nox Force ncurses use. FILES
/etc/ppp/peers/dsl-provider is pppd options file for your dsl provider. /etc/ppp/pap-secrets and /etc/ppp/chap-secrets are described in pppd documentation. pppoeconf may add lines to theses files. /etc/ppp/ip-up.d/0clampmss and /etc/ppp/ip-down.d/0clampmss are used to clamp MSS if needed. /etc/network/interfaces is network interface file for your system. SEE ALSO
pppd(8), interfaces(5), pon(1) and pppoe(8). AUTHOR
This manual page was originally written by Eduard Bloch (blade@debian.org) and now maintained by Gregory Colpart (reg@evolix.fr) for the Debian GNU/Linux system (but may be used by others). This document is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. PPPOECONF(8)
All times are GMT -4. The time now is 06:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy