perl : merging two arrays on basis of common parameter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl : merging two arrays on basis of common parameter
# 1  
Old 02-10-2011
perl : merging two arrays on basis of common parameter

I have 2 arrays,

@array1 contains records in the format
Code:
1|_|X|_|ssd|_|
4|_|H|_|hbd|_|
9|_|Y|_|u8gjdfg|_|

@array2 contains records in the format
Code:
X|_|asdf|_|
Y|_|qwer|_|
A|_|9kdkf|_|

@array3 should contain records in the PLz
Code:
X|_|ssd|_|asdf|_|
Y|_|hdb|_|qwer|_|

PLZ dont use nawk command .
I want to know if theres a command in perl analogous to nawk.


It should be very fast.

Last edited by radoulov; 02-10-2011 at 05:16 AM.. Reason: Code tags, please!
# 2  
Old 02-10-2011
I don't understand: I suppose you mean input data, not array?
If this is part of a larger Perl script, please post the relevant part of the actual code.
# 3  
Old 02-10-2011
See array1 2nd parameter (if spliting parameter is |_|)
Similarly array2's 1st parameter ( if splitting parameter is |_|)

If this above 2 parameters match put that particular record in array3 in the format shown.


Its basically merging two arrays based on a particular column

Last edited by centurion_13; 02-10-2011 at 06:23 AM.. Reason: missed some data
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merging 2 Arrays in a script

I am creating (with help) my own version of a calculator script that simply merges 2 arrays ( ${a}${b}${a}${b}... etc ) #!/bin/bash echo "Enter the integers you would like to calculate" read -a nums echo "You entered ${#nums} integers" let batch="${#nums}-1" echo "Enter how you want to... (2 Replies)
Discussion started by: pbmitch
2 Replies

2. Shell Programming and Scripting

Merging 2 Arrays

I am trying to create a script that combines 2 arrays: #!/bin/bash read -a unix #(a c e g) read -a test #(b d f) #now I want to merge ${unix} with ${test}, one after another such that the result would be: (abcdefg) #I've tried quite a few options and can't seem to make it work (5 Replies)
Discussion started by: pbmitch
5 Replies

3. Shell Programming and Scripting

Merging two files without any common pattern

Hi I have file1 as IJU_NSOMOW; SOWWOD_TWUIQ; and file2 as how are you?; fine there; Now my problem is i need the output file as IJU_NSOMOW; how are you?; SOWWOD_TWUIQ; fine there; (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

4. Shell Programming and Scripting

Merging files with common IDs without JOIN

Hi, I am trying to merge information across 2 files. The first file is a "master" file, with all IDS. File 2 contains a subset of IDs of those in File 1. I would like to match up individuals in File 1 and File 2, and add information in File 2 to that of File 1 if they appear. However, if an... (3 Replies)
Discussion started by: hubleo
3 Replies

5. UNIX for Dummies Questions & Answers

Merging tables: identifiying common and unique elements

Hi all, I know how to merge two tables and to remove the duplicated lines based on a field (Column 2) . My next challenge is to be able to identify in a new column those common elements between table A & B, those elements in table A not present in table B and vice versa. A simple count would be... (6 Replies)
Discussion started by: lsantome
6 Replies

6. Shell Programming and Scripting

Merging CSV fields based on a common field

Hi List, I have two files. File1 contains all of the data I require to be processed, and I need to add another field to this data by matching a common field in File2 and appending a corresponding field to the data in File1 based on the match... So: File 1:... (1 Reply)
Discussion started by: landossa
1 Replies

7. Shell Programming and Scripting

Merging 2 files based on a common column

Hi All, I do have 2 files file 1 has 4 tab delimited columns 234 a c dfgyu 294 b g fih 302 c h jzh 328 z c san 597 f g son File 2 has 2 tab delimted columns 234 23 302 24 597 24 I want to merge file 2 with file 1 based on the data common in both files which is the first column so... (6 Replies)
Discussion started by: Lucky Ali
6 Replies

8. Shell Programming and Scripting

Group on the basis of common text in the square bracket and sorting

File A 99 >ac >ss >juk 70 >acb >defa 90 >ca 100 >aa >abc >bca 85 >cde 81 >ghi >ghij 87 >def >fgh <ijk 89 >fck >ghij >kill >aa The given output shud be 100 >aa >abc >bca 87 >def >fgh <ijk 89 >fck >ghij >kill >aa (2 Replies)
Discussion started by: cdfd123
2 Replies

9. Shell Programming and Scripting

Merging arrays

Hi all, I need some help in merging arrays. I have two arrays and using korn shell Array1 AB23 AB24 Array2 CD00 CD01 CD02 Elements from array 1 should always alternate with elements of arrays 2 i.e the result should look like AB23CD00 AB24CD01 AB23CD02 Any help is appreciated.... (4 Replies)
Discussion started by: jakSun8
4 Replies

10. Shell Programming and Scripting

Merging two files with a common column

Hi, I have two files file1 and file2. I have to merge the columns of those two files into file3 based on common column of two files. To be simple. file1: Row-id name1 13456 Rahul 16789 Vishal 18901 Karan file2 : Row-id place 18901 Mumbai ... (2 Replies)
Discussion started by: manneni prakash
2 Replies
Login or Register to Ask a Question