Sponsored Content
Top Forums Shell Programming and Scripting Creating array with non-duplicate / unique elements in ksh Post 302809845 by sanzee007 on Monday 20th of May 2013 11:45:30 PM
Old 05-21-2013
Creating array with non-duplicate / unique elements in ksh

Hi all,
I have created 3 arrays which can have common elements in each like-
arr_a contains str1 str2 str3 str4 str5
arr_b contains str3 str6 str7 str1 str8
arr_c contains str4 str9 str10 str2

each array is created with "set -A arr_name values" command. I want to create a resultant array-say arr_a, which will contain the merging of the above 3 arrays without any duplicate elements like-
arr_a str1 str2 str3 str4 str5 str6 str7 str8 str9 str10

I can merge the array with the same 'set -A arr_a ${arr_a[*]} ${arr_b[*]} ${arr_c[*]}' command, however it contains duplicate elements. Is ther any option i can provide with 'set' to create array with unique elements??

Considering looping is not the right option as the time complexity will directly proportional to the total elements in individual array. So please consider this while providing input.

thanks in advance for the replies.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

creating a dynamic array in ksh

Hi, Is it possible to create a dynamic array in shell script. I am trying to get the list of logfiles that created that day and put it in a dynamic array. I am not sure about it. help me New to scripting Gundu (3 Replies)
Discussion started by: gundu
3 Replies

2. Shell Programming and Scripting

To return the elements of array

Hi, Please can someone help to return the array elements from a function. Currently the problem I face is that tempValue stores the value in myValue as a string while I need an array of values to be returned instead of string. Many Thanks, Sudhakar the function called is: ... (5 Replies)
Discussion started by: Sudhakar333
5 Replies

3. Shell Programming and Scripting

Creating an Array in KSH from output (stdout)

Using Cygwin PDksh - But also have tested it on Linux with same results ---- I have a script that invokes a program/script and returns a string of data (1234 "12 34 56" 6789) and using "set -A" inserting it into an array. script code snipit >> get_array=$(php... (2 Replies)
Discussion started by: carlos25
2 Replies

4. Shell Programming and Scripting

check duplicate elements

hi if i have arry with lots of intergers , how to check if there is duplicate integers in perl ? say I ahve @intergers=( 1,2,3,3,4,5,4,99,99,100) (2 Replies)
Discussion started by: james94538
2 Replies

5. UNIX for Dummies Questions & Answers

Help with replacing Array elements

Hi, I have an array containing following sample information @array = qw (chr02 chr02 chr02 chr02 chr02 chr03 chr03 chr04 chr04 chr05 chr05 chr05 chr07 chr07) I need to replace all duplicate entries by an underscore to get the following output@array = qw (chr02 _ _ _ _ chr03 _ chr04 _ chr05 _ _... (4 Replies)
Discussion started by: pawannoel
4 Replies

6. Shell Programming and Scripting

Removing elements from an array

Hi I have two arrays : @arcb= (450,625,720,645); @arca=(625,645); I need to remove the elements of @arca from elements of @arcb so that the content of @arcb will be (450,720). Can anyone sugget me how to perform this operation? The code I have used is this : my @arcb=... (3 Replies)
Discussion started by: rkrish
3 Replies

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

8. Shell Programming and Scripting

Help reading the array and sum of the array elements

Hi All, need help with reading the array and sum of the array elements. given an array of integers of size N . You need to print the sum of the elements in the array, keeping in mind that some of those integers may be quite large. Input Format The first line of the input consists of an... (1 Reply)
Discussion started by: nishantrefound
1 Replies

9. UNIX for Beginners Questions & Answers

Awk: count unique elements in a field and sum their occurence across the entire file

Hi, Sure it's an easy one, but it drives me insane. input ("|" separated): 1|A,B,C,A 2|A,D,D 3|A,B,B I would like to count the occurence of each capital letters in $2 across the entire file, knowing that duplicates in each record count as 1. I am trying to get this output... (5 Replies)
Discussion started by: beca123456
5 Replies

10. Shell Programming and Scripting

Get unique elements from Array

I have an array code and output is below: echo $1 while read -r fline; do echo "%%%%%%$fline%%%%%" fmy_array+=("$fline") done <<< "$1" Output: CR30903 YU0007 SRIL CR30903 Yogesh SRIL %%%%%%CR30903 YU0007 SRIL%%%%% %%%%%%CR30903 Yogesh SRIL%%%%% ... (8 Replies)
Discussion started by: mohtashims
8 Replies
Unicode::Escape(3pm)					User Contributed Perl Documentation				      Unicode::Escape(3pm)

NAME
Unicode::Escape - Escape and unescape Unicode characters other than ASCII VERSION
This document describes Unicode::Escape version 0.0.1 SYNOPSIS
# Escape Unicode charactors like '\u3042\u3043\u3044'. # JSON thinks No more Garble!! # case 1 use Unicode::Escape; my $escaped1 = Unicode::Escape::escape($str1, 'euc-jp'); # $str1 contains charactor that is not ASCII. $str1 is encoded by euc-jp. my $escaped2 = Unicode::Escape::escape($str2); # default is utf8 # $str2 contains charactor that is not ASCII. my $unescaped1 = Unicode::Escape::unescape($str3, 'shiftjis'); # $str3 contains escaped Unicode character. return value is encoded by shiftjis. my $unescaped2 = Unicode::Escape::unescape($str4); # default is utf8 # $str4 contains escaped Unicode character. # case 2 use Unicode::Escape qw(escape unescape); my $escaped1 = escape($str1, 'euc-jp'); # $str1 contains charactor that is not ASCII. $str1 is encoded by euc-jp. my $escaped2 = escape($str2); # default is utf8 # $str2 contains charactor that is not ASCII. my $unescaped1 = unescape($str3, 'shiftjis'); # $str3 contains escaped Unicode character. return value is encoded by shiftjis. my $unescaped2 = unescape($str4); # default is utf8 # $str4 contains escaped Unicode character. # case 3 use Unicode::Escape; my $escaper = Unicode::Escape->new($str, 'shiftjis'); # $str contains charactor that is not ASCII. $str is encoded by shiftjis.(default is utf8) my $escaped = $escaper->escape; # case 4 use Unicode::Escape; my $escaper = Unicode::Escape->new($str); # $str contains escaped Unicode character. my $unescaped1 = $escaper->unescape('shiftjis'); my $unescaped2 = $escaper->unescape; # default is utf8. DESCRIPTION
Escape and unescape Unicode characters other than ASCII. When the server response is javascript code, it is convenient. METHODS
new( $string[, $encode ] ) string Target string for escape or unescape. encode For instance, 'utf8', 'shiftjis', and 'euc-jp', etc. (See Encode) escape( $string[, $encode ] ) string Target string. This argument is unnecessary when called as object method. encode For instance, 'utf8', 'shiftjis', and 'euc-jp', etc. (See Encode) This argument is unnecessary when called as object method. unescape( $string[, $encode ] ) string Target string. This argument is unnecessary when called as object method. encode For instance, 'utf8', 'shiftjis', and 'euc-jp', etc. (See Encode) SEE ALSO
Unicode::String, Encode INCOMPATIBILITIES
None reported. BUGS AND LIMITATIONS
No bugs have been reported. Please report any bugs or feature requests to "bug-unicode-escape@rt.cpan.org", or through the web interface at <http://rt.cpan.org>. AUTHOR
Hitoshi Amano "<seijro@gmail.com>" LICENCE AND COPYRIGHT
Copyright (c) 2006, Hitoshi Amano "<seijro@gmail.com>". All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. perl v5.12.3 2011-06-05 Unicode::Escape(3pm)
All times are GMT -4. The time now is 02:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy