awk command for simple join command but based on 2 columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk command for simple join command but based on 2 columns
# 1  
Old 03-28-2010
awk command for simple join command but based on 2 columns

input1

Code:
a_a    a/a    10    100
a1    a_a    20    200
b1    b_b    30    300

input2

Code:
a_a    a/a    xxx    yyy
a1    a1    lll    ppp
b1    b_b    kkk    ooo


output
Code:
a_a    a/a    10    100    xxx    yyy
b1    b_b    30    300    kkk    ooo

# 2  
Old 03-28-2010
One way in awk:
Code:
awk 'NR==FNR{A[$1,$2]=$3t$4;next} A[$1,$2]{print $1t$2t A[$1,$2] t$3t$4}' t="\t" file1 file2

Output
Code:
a_a     a/a     10      100     xxx     yyy
b1      b_b     30      300     kkk     ooo

# 3  
Old 03-28-2010
heyyy

Thank you soo soo much. It's working great! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join, merge, fill NULL the void columns of multiples files like sql "LEFT JOIN" by using awk

Hello, This post is already here but want to do this with another way Merge multiples files with multiples duplicates keys by filling "NULL" the void columns for anothers joinning files file1.csv: 1|abc 1|def 2|ghi 2|jkl 3|mno 3|pqr file2.csv: 1|123|jojo 1|NULL|bibi... (2 Replies)
Discussion started by: yjacknewton
2 Replies

2. Shell Programming and Scripting

Join columns across multiple lines in a Text based on common column using BASH

Hello, I have a file with 2 columns ( tableName , ColumnName) delimited by a Pipe like below . File is sorted by ColumnName. Table1|Column1 Table2|Column1 Table5|Column1 Table3|Column2 Table2|Column2 Table4|Column3 Table2|Column3 Table2|Column4 Table5|Column4 Table2|Column5 From... (6 Replies)
Discussion started by: nv186000
6 Replies

3. Shell Programming and Scripting

Simple awk command to compare two files and print first difference

Hello, I have two text files, each with a single column, file 1: 124152970 123899868 123476854 54258288 123117283 file 2: 124152970 123899868 54258288 123117283 122108330 (5 Replies)
Discussion started by: LMHmedchem
5 Replies

4. Shell Programming and Scripting

A simple awk command

Hi there, given the file FIELD1 FIELD2 FIELD3 FIELD4 FIELD5 FIELD6 FIELD7 FIELD8 FIELD9 FIELD10 FIELD11 Why does not awk '$6 == "FIELD6" {$6=="GREEN"}1' file do the work and replace"FIELD6" by "GREEN"? And second question, what is the purpose of the "1" at the end of... (5 Replies)
Discussion started by: la2015
5 Replies

5. Shell Programming and Scripting

awk command to replace columns in 2 files

Hi All, I already have a code which replaces column 14 of NPBR.XTR.tmp with column 8 of NPBR3G.XTR.final awk -F'\|' 'FNR==NR{a= $2"^"$8;next;}a{split(a,b,"^");$8=b;$14=b;}1' OFS="|" ${SHTEMP}NPBR3G.XTR.final ${SHTEMP}NPBR.XTR.tmp > ${SHTEMP}NPBR.XTR.final I also need to replace column 15... (2 Replies)
Discussion started by: nua7
2 Replies

6. UNIX for Dummies Questions & Answers

How to use the the join command to join multiple files by a common column

Hi, I have 20 tab delimited text files that have a common column (column 1). The files are named GSM1.txt through GSM20.txt. Each file has 3 columns (2 other columns in addition to the first common column). I want to write a script to join the files by the first common column so that in the... (5 Replies)
Discussion started by: evelibertine
5 Replies

7. Shell Programming and Scripting

awk command to print multiple columns

Hello Team, I have written following command which is giving output is as shown below. bash-3.00$ grep -i startup catalina.out | tail +2 | sed -n 1p | awk -F" " '{ for (x=1; x<=5; x++) { printf"%s\n", $x } }' Dec 19, 2010 3:28:39 PM bash-3.00$ I would like to modify above command to... (2 Replies)
Discussion started by: coolguyamy
2 Replies

8. UNIX for Dummies Questions & Answers

Join 2 files with multiple columns: awk/grep/join?

Hello, My apologies if this has been posted elsewhere, I have had a look at several threads but I am still confused how to use these functions. I have two files, each with 5 columns: File A: (tab-delimited) PDB CHAIN Start End Fragment 1avq A 171 176 awyfan 1avq A 172 177 wyfany 1c7k A 2 7... (3 Replies)
Discussion started by: InfoSeeker
3 Replies

9. Shell Programming and Scripting

awk or python to join alternating columns

Hi, here is my input TEST-SAM-A6ZZ SM-S6KV 0 0 2 1 2 3 3 3 2 2 2 2 1 1 2 2 1 3 1 3 1361 SM-HA4Q 0 0 2 1 3 3 3 3 2 2 2 2 1 1 2 2 1 3 3 3 4 2 4 2 2 276217 SM-H9ZG 0 0 2 2 3 3 3 3 2 2 2 2 1 1 2 2 3 3 1 3 2 2 2 2 GC15458 SM-HAQX 0 0 2 1 2 3 1 3 2 2 2 2 1 1 2 2 1 3 1 3 2 2 2 18331 SM-HA5E 0 0 2 2... (2 Replies)
Discussion started by: genehunter
2 Replies

10. Shell Programming and Scripting

Simple AWK command?

I am not that good with AWK. Is there a simple awk command I could use to get the word "this" from the following text besides using "awk -F ":" '{print $2} | awk -F " " '{print $1}"? :this is:that is: (6 Replies)
Discussion started by: 2dumb
6 Replies
Login or Register to Ask a Question