Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Linux/Shell script - How to compare 2 arrays based on patterns and get the differences Post 303041897 by RudiC on Friday 6th of December 2019 05:56:49 AM
Old 12-06-2019
Try also
Code:
IFS="|" read -a A1 <file1
IFS="|" read -a A2 <file2
IFS=$'\n'
<<< "${A1[*]}$IFS${A2[*]}$IFS${A2[*]}" sort | uniq -u
B
D
E
G
H
STATUS

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell: creating different arrays based on function argument

hi, I was wondering if there was a good way to create an array within a function, where the name is based on a passed argument? I tried this: _____________________________ func(){ #take in 1st arg as the arrayname arrayName=$1 let i=0 while read line do arrayName=${line} let i+=1... (5 Replies)
Discussion started by: nix21
5 Replies

2. Shell Programming and Scripting

Compare two arrays in sh or compare two fields

I want a soultion to compare two arrays in sh with an easy way.I want a solution to synchrose users between different AIX servers where no NIS is available. All users are meant to be same on all 10 servers. So the approach is to consider first server as master user repository and whatever the users... (0 Replies)
Discussion started by: rijeshpp
0 Replies

3. Shell Programming and Scripting

script to edit strings based on patterns

Hello All, Here is the file which I want to edit. The script should look for DB2 and if found then delete all lines related to DB2 connection string. Is there way this can be done using script ? DB1 = (DESCRIPTION = (SDU = 32768 (enable = broken) (ADDRESS = (PROTOCOL =... (2 Replies)
Discussion started by: deepakc_in
2 Replies

4. Shell Programming and Scripting

shell script to format file based on specific patterns

Please help me out and drag me out the deadlock I am stuck into: I have a file. I want the statements under a if...then condition be listed in a separate file in the manner condition|statement.Following are the different input pattern and corresponding output parameters.any generic code to... (7 Replies)
Discussion started by: joyan321
7 Replies

5. Shell Programming and Scripting

differences in linux and unix shell

hi all, can any one plz tell me that what is the difference between linux shell scripting and unix shell scripting. is there any difference at all?? if yes that what are the differences and how could it be combatted thanks in advance (1 Reply)
Discussion started by: nasir_khan
1 Replies

6. Shell Programming and Scripting

Comparing 2 arrays but ignoring certain patterns

I'm trying to compare 2 array and print the difference at a 3rd file. However how am i going to compare this 2 arrays by ignoring certain patterns: For example: 1st array contains: ctahci cptcsa0 ctsata:25:seed cptcsa1:50:seed ctsata_1:25:seed 2nd array contains: cptcsa0 ctsata... (0 Replies)
Discussion started by: hongping
0 Replies

7. Shell Programming and Scripting

Linux shell script to insert new lines based on delimiter count

The input file is a .dat file which is delimited by null (^@ in Linux). On a windows PC it looks something like this (numbers are masked with 1). https://i.imgur.com/nta2Gqp.jpg The entire file is in one row but it has multiple records - each record contains 80 fields i.e. there are 81 counts... (9 Replies)
Discussion started by: digitalnirvana
9 Replies

8. Shell Programming and Scripting

Compare two big files for differences using Linux

Hello everybody Looking for help in comparing two files in Linux(files are big 800MB each). Example:- File1 has below data $ cat file1 5,6,3 2.1.4 1,1,1 8,9,1 File2 has below data $ cat file2 5,6,3 8,9,8 1,2,1 2,1,4 (1 Reply)
Discussion started by: shanul karim
1 Replies

9. UNIX for Beginners Questions & Answers

Compare two big files for differences using Linux

Hello everybody Looking for help in comparing two files in Linux(files are big 800MB each). Example:- File1 has below data $ cat file1 5,6,3 2.1.4 1,1,1 8,9,1 File2 has below data $ cat file2 5,6,3 8,9,8 1,2,1 2,1,4 (8 Replies)
Discussion started by: shanul karim
8 Replies

10. UNIX for Beginners Questions & Answers

Shell Script to Compare Files and Email the differences

Hi, I have 2 files abc.txt and bdc.txt. I am using $diff -y abc.txt bcd.txt -- compared the files side by side I would like to write a Shell Script to cmpare the files side by side and print the results( which are not matched) in a side by side format and save the results in another... (10 Replies)
Discussion started by: vasuvv
10 Replies
ARRAY_DIFF_UASSOC(3)							 1						      ARRAY_DIFF_UASSOC(3)

array_diff_uassoc - Computes the difference of arrays with additional index check which is performed by a user supplied callback function

SYNOPSIS
array array_diff_uassoc (array $array1, array $array2, [array $...], callable $key_compare_func) DESCRIPTION
Compares $array1 against $array2 and returns the difference. Unlike array_diff(3) the array keys are used in the comparison. Unlike array_diff_assoc(3) an user supplied callback function is used for the indices comparison, not internal function. PARAMETERS
o $array1 - The array to compare from o $array2 - An array to compare against o $... - More arrays to compare against o $key_compare_func - The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. int callback (mixed $a, mixed $b) RETURN VALUES
Returns an array containing all the entries from $array1 that are not present in any of the other arrays. EXAMPLES
Example #1 array_diff_uassoc(3) example The "a" => "green" pair is present in both arrays and thus it is not in the output from the function. Unlike this, the pair 0 => "red" is in the output because in the second argument "red" has key which is 1. <?php function key_compare_func($a, $b) { if ($a === $b) { return 0; } return ($a > $b)? 1:-1; } $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); $array2 = array("a" => "green", "yellow", "red"); $result = array_diff_uassoc($array1, $array2, "key_compare_func"); print_r($result); ?> The above example will output: Array ( [b] => brown [c] => blue [0] => red ) The equality of 2 indices is checked by the user supplied callback function. NOTES
Note This function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using, for example, array_diff_uassoc($array1[0], $array2[0], "key_compare_func");. SEE ALSO
array_diff(3), array_diff_assoc(3), array_udiff(3), array_udiff_assoc(3), array_udiff_uassoc(3), array_intersect(3), array_inter- sect_assoc(3), array_uintersect(3), array_uintersect_assoc(3), array_uintersect_uassoc(3). PHP Documentation Group ARRAY_DIFF_UASSOC(3)
All times are GMT -4. The time now is 09:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy