Join columns from 2 files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Join columns from 2 files
# 1  
Old 11-13-2007
Join columns from 2 files

Hello guys.

I need to join columns of Start Time and End time of 2 files.

The Examples is:

File 1

APPLICATION GROUP_NAME JOB_NAME ODATE STATUS START_TIME END_TIME ::

MODCMPDA EDPONLINE MC00A1700 071102 Ended OK 20071102 17:00:01

File 2

APPLICATION GROUP_NAME JOB_NAME ODATE STATUS START_TIME END_TIME ::

MODCMPDA EDPONLINE MC210A0701 071101 Ended OK 20071101 07:05:02 20071101 07:05:10

The result i'm expecting is :

APPLICATION GROUP_NAME JOB_NAME ODATE STATUS START_TIME END_TIME ::

MODCMPDA EDPONLINE MC210A0701 071101 Ended OK " date of file1" " hh:mm:ss of file 1 " hh:mm:ss of file2 "

Can someone give me an and ?

Thanks
# 2  
Old 11-14-2007
awk

Hi,

This one should be ok for you.

code:
Code:
awk '
{
if(NF==8)
{
	var1[$2]=$7
	var2[$2]=$8
}
else
{
$7=var1[$2]
$8=var2[$2]
$9=$10
NF=9
print
}
}' file1 file2

# 3  
Old 11-14-2007
Join columns from 2 files

Hello.

Maybe i didn't explain well.

I want to put :

File 1

APPLICATION GROUP_NAME JOB_NAME ODATE STATUS START_TIME END_TIME ::

MODCMPDA EDPONLINE MC00A1700 071102 Ended OK 20071102 17:00:01 17:00:10

File 2

APPLICATION GROUP_NAME JOB_NAME ODATE STATUS START_TIME END_TIME ::

MODCMPDA EDPONLINE MC210A0701 071101 Ended OK 20071101 07:05:02 20071101 07:05:10

that means from file 1 i want to have an last file with FIELDS 1 to 7 with FIELD 10 from file2 .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Data match 2 files based on first 2 columns matching only and join if match

Hi, i have 2 files , the data i need to match is in masterfile and i need to pull out column 3 from master if column 1 and 2 match and output entire row to new file I have tried with join and awk and i keep getting blank outputs or same file is there an easier way than what i am... (4 Replies)
Discussion started by: axis88
4 Replies

2. 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

3. Shell Programming and Scripting

Join and merge multiple files with duplicate key and fill void columns

Join and merge multiple files with duplicate key and fill void columns Hi guys, I have many files that I want to merge: file1.csv: 1|abc 1|def 2|ghi 2|jkl 3|mno 3|pqr file2.csv: (5 Replies)
Discussion started by: yjacknewton
5 Replies

4. Shell Programming and Scripting

Join two files combining multiple columns and produce mix and match output

I would like to join two files when two columns in each file matches with each other and then produce an output when taking multiple columns. Like I have file A 1234,ABCD,23,JOHN,NJ,USA 2345,ABCD,24,SAM,NY,USA 5678,GHIJ,24,TOM,NY,USA 5678,WXYZ,27,MAT,NJ,USA and file B ... (2 Replies)
Discussion started by: mady135
2 Replies

5. Shell Programming and Scripting

Join two lines into one, but the second line only the last two columns

Hi guys, I hope you are doing well! I have a file and I need to join two lines into one, but the second line I need only the last two columns. ================= "eHealth Trend Report","logoRpt" "LAN/WAN Group 123" "Divide by Time" "switch1_a-RH-Serial0" "BW: 1.02 M" ... (4 Replies)
Discussion started by: antoniorajr
4 Replies

6. Shell Programming and Scripting

Join two files with matching columns

Hi, I need to join two files together with one common value in a column. I think I can use awk or join or a combination but I can't quite get it. Basically my data looks like this, with the TICKER columns matching up in each file File1 TICKER,column 1, column, 2, column, 3, column 4 ... (6 Replies)
Discussion started by: unkleruckus
6 Replies

7. Shell Programming and Scripting

Sort and join multiple columns using awk

Is it possible to join all the values after sorting them based on 1st column key and replace empty rows with 0 like below ? input a1 0 a1 1 a1 1 a3 1 b2 1 a2 1 a4 1 a2 1 a4 1 c4 1 a3 1 d1 1 a3 1 b1 1 d1 1 a4 1 c4 1 b2 1 b1 1 b2 1 c4 1 d1 1 output... (8 Replies)
Discussion started by: quincyjones
8 Replies

8. Shell Programming and Scripting

Join 4 files on first three columns

Hi, Can someone suggest me on how to join 4 files by comparing the first three columns? ---------- Post updated at 03:56 PM ---------- Previous update was at 03:42 PM ---------- Hope it helps someone. I was looking online for a solution and on stackoverflow, I found a solution and tried... (6 Replies)
Discussion started by: jacobs.smith
6 Replies

9. 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

10. 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
Login or Register to Ask a Question