Sponsored Content
Top Forums Shell Programming and Scripting combining 2 files with more than one match in second file Post 302148894 by summer_cherry on Tuesday 4th of December 2007 04:01:44 AM
Old 12-04-2007
awk

hi,

Up to now, it seems the most difficult one for me. And it really took me much time to find out the solution. Hope this can help you.

code:
Code:
nawk 'BEGIN{
FS=","
n=1
}

function isExist(k)
{
	flag=0
	for ( i in name)
	{	if(name[i]==k)
			flag=i
	}
	return flag
}

{
if (NR==FNR)
{
	name[n]=$1
	con[n]=$2
	n++
}
else
{
	if(isExist($1)!=0)
		con[isExist($1)]=sprintf("%s,%s",con[isExist($1)],$2)
}
}
END{
for (i=0;i<n;i++)
if (index(con[i],",")!=0)
	print name[i]","con[i]
else
	print name[i]","con[i]",NO_SERIAL_FOUND"
}' file1 file2

 

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
CUBRID_DISCONNECT(3)							 1						      CUBRID_DISCONNECT(3)

cubrid_disconnect - Close a database connection

SYNOPSIS
bool cubrid_disconnect ([resource $conn_identifier]) DESCRIPTION
The cubrid_disconnect(3) function closes the connection handle and disconnects from server. If any request handle is not closed at this point, it will be closed. It is similar to the CUBRID MySQL compatible function cubrid_close(3). PARAMETERS
o $conn_identifier -Connection identifier. RETURN VALUES
TRUE, when process is successful. FALSE, when process is unsuccessful. EXAMPLES
Example #1 cubrid_disconnect(3) example <?php $con = cubrid_connect ("localhost", 33000, "demodb"); if ($con) { echo "connected successfully"; $req = cubrid_execute( $con, "create table person(id int,name char(10))"); if ($req) { cubrid_close_request($req); cubrid_commit($con); } else { cubrid_rollback($con); } $req = cubrid_execute( $con, "insert into person values(1,'James')"); if ($req) { cubrid_close_request($req); cubrid_commit($con); } else { cubrid_rollback($con); } cubrid_disconnect($con); } ?> SEE ALSO
cubrid_close(3), cubrid_connect(3), cubrid_connect_with_url(3). PHP Documentation Group CUBRID_DISCONNECT(3)
All times are GMT -4. The time now is 09:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy