Sponsored Content
Top Forums Shell Programming and Scripting combining 2 files with more than one match in second file Post 302148900 by rikxik on Tuesday 4th of December 2007 04:53:50 AM
Old 12-04-2007
Here goes using awk:

File1:
Quote:
$ cat f1.txt
bob,232
fred,202
jim,202
pat,232
sam,232
ted,118
tim,118
File2:
Quote:
$ cat f2.txt
ialan,TEW9873FG
bob,XVT81283WS
fred,YHW81342BB
fred,YHW83281BA
fred,YHW98746CR
jake,QWE9896AQ
pat,LKJ55432GH
sam,QER8984UH
sam,QER6536WE
sam,QER2343ET
sid,ASW9093TW
ted,OPW4324TY
val,RWT6492OK
Script:
Quote:
$ cat merge.awk
BEGIN {
first=FILENAME
while (getline > 0) {
split($0, a, ",");
x=a[1]; y=a[2]
if (FILENAME == first) {
arr[x] = $0
} else {
if (brr[x] == "") {
brr[x] = y
} else {
brr[x] = brr[x]";"y
}
}
}
}

END {
for (i in arr) {
if(brr[i] == "") {
xrr[i] = arr[i]",NO_SERIAL_FOUND"
} else {
xrr[i] = arr[i]","brr[i]
}
print xrr[i]
}
}
Output:
Quote:
$ awk -f merge.awk f1.txt f2.txt
bob,232,XVT81283WS
ted,118,OPW4324TY
fred,202,YHW81342BB;YHW83281BA;YHW98746CR
jim,202,NO_SERIAL_FOUND
sam,232,QER8984UH;QER6536WE;QER2343ET
pat,232,LKJ55432GH
tim,118,NO_SERIAL_FOUND
HTH
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare two csv files by two colums and create third file combining data from them.

I've got two large csv text table files with different number of columns each. I have to compare them based on first two columns and create resulting file that would in case of matched first two columns include all values from first one and all values (except first two colums) from second one. I... (5 Replies)
Discussion started by: agb2008
5 Replies

2. UNIX for Dummies Questions & Answers

Combining lines of files to new file

Hi everybody. I have a number of files that i would like to combine. however not concatenating, but rather extract lines from the files. Example: File1 ------ File2 ------File3 ... line11 ---- line21 ---- line31 ... line12 ---- line22 ---- line32 ... line13 ... (3 Replies)
Discussion started by: kabbo
3 Replies

3. UNIX for Dummies Questions & Answers

Assistance with combining, sorting and saving multi files into one new file

Good morning. I have a piece of code that is currently taking multiple files and using the CAT.exe command to combine into one file that is then sorted in reverse order based on the 3rd field of the file, then displayed on screen. I am trying to change this so that the files are being combined into... (4 Replies)
Discussion started by: jaacmmason
4 Replies

4. Shell Programming and Scripting

Combining columns from multiple files to one file

I'm trying to combine colums from multiple file to a single file but having some issues, appreciate your help. The filenames are the same except for the extension, path1.m0 --------- a b c d e f g h i path1.m1 --------- m n o p q r s t u File names are path1.m The... (3 Replies)
Discussion started by: rkmca
3 Replies

5. UNIX for Dummies Questions & Answers

Need Help in reading N days files from a Directory & combining the files

Hi All, Request your expertise in tackling one requirement in my project,(i dont have much expertise in Shell Scripting). The requirement is as below, 1) We store the last run date of a process in a file. When the batch run the next time, it should read this file, get the last run date from... (1 Reply)
Discussion started by: dsfreddie
1 Replies

6. Shell Programming and Scripting

Combining multiple column files into one with file name as first row

Hello All, I have several column files like this $cat a_b_s1.xls 1wert 2tg 3asd 4asdf 5asdf $cat c_d_s2.xls 1wert 2tg 3asd 4asdf 5asdf desired put put $cat combined.txt s1 s2 (2 Replies)
Discussion started by: avatar_007
2 Replies

7. Shell Programming and Scripting

Combining columns from multiple files into one single output file

Hi, I have 3 files with one column value as shown File: a.txt ------------ Data_a1 Data_a2 File2: b.txt ------------ Data_b1 Data_b2 Data_b3 Data_b4 File3: c.txt ------------ Data_c1 Data_c2 Data_c3 Data_c4 Data_c5 (6 Replies)
Discussion started by: vfrg
6 Replies

8. Shell Programming and Scripting

Combining files(every 15 min) as one file(hourly)

Hello, My system is generating two files every 15 minutes and file names are given automatically as below. (98,99,89,90 are the sequence numbers) File1_09242013131016_000000098 File1_09242013131516_000000099 File2_09242013124212_000000089 File2_09242013124712_000000090 I want to combine... (6 Replies)
Discussion started by: phoenex11
6 Replies

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

10. Shell Programming and Scripting

Combining certain columns of multiple files into one file

Hello Unix gurus, I have a large number of files (say X) each containing two columns of data and the same number of rows. I would like to combine these files to create a unique merged file containing X columns corresponding to the second column of each file (with a bonus of having the first... (3 Replies)
Discussion started by: ksennin
3 Replies
UMCT(4) 						   BSD Kernel Interfaces Manual 						   UMCT(4)

NAME
umct -- Magic Control Technology USB-RS232 converter driver SYNOPSIS
To compile this driver into the kernel, place the following lines in your kernel configuration file: device umct device ucom Alternatively, to load the driver as a module at boot time, place the following line in loader.conf(5): umct_load="YES" DESCRIPTION
The umct driver provides support for USB to RS-232 converters based on the Magic Control Technology USB-232 design. These devices support most of the standard RS-232 features including baud rates ranging from 300 to 115200 bits per second. However, neither hardware nor software flow control seems to be supported. Access to devices under this driver is via the ucom(4) framework and device nodes. HARDWARE
The umct driver supports the following adapters: o Belkin F5U109 o Belkin F5U409 o D-Link DU-H3SP USB BAY Hub o Magic Control Technology USB-232 o Sitecom USB-232 SEE ALSO
tty(4), ucom(4), usb(4) HISTORY
The umct driver appeared in FreeBSD 5.2. It is loosely based on the ubsa(4) driver by Alexander Kabaev <kan@FreeBSD.org> with documentation from Wolfgang Grandeggar <wolfgang@cec.ch>. AUTHORS
The umct driver was written by Scott Long <scottl@FreeBSD.org>. BSD
November 22, 2006 BSD
All times are GMT -4. The time now is 07:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy