Cleaning up Arrays with duplicate values

Hey Gang!

So I have two Arrays. @linecount and @hit. Now these arrays contain numbers which I'm using as line placeholders on files. I need these two arrays to sync up and not repeat a number.

Here are the contents (spam alert)

@linecount

1
28
53
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
175
175
175
176
176
177

and Here is

@hit

21
31
54
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
176
177
178
177
178
178

Notice how some of them have the same numbers, multiple times? I need it to quit that and merge them into a singular array with no duplicating numbers.

I hope this makes sense.

Something like this:

@merge{@linecount, @hit} = (1) x @linecount + @hit;
@all_unique = sort { $a <=> $b } keys %merge;

Hi

you can place the two arrays in two files- file1 and file2.

cat file2 >> file1 
sort -nu file1

Spam in, spam out :smiley: (Not sure I'm getting you right, though ...)

[house@leonov] cat data1
175
175
175
176
176
177
[house@leonov] cat data2
176
177
178
177
178
178
[house@leonov] paste data1 data2 | awk 'BEGIN {X=0} {if (X!=$1) {print $0; X=$1}}'
175     176
176     177
177     178

Another way (assume sorted input files)

$ cat adelsin_1.txt
1
1
2
2
5
6
9
$ cat adelsin_2.txt
2
2
3
4
7
8
8
8
9
9
$ join -a 1 -a 2 adelsin_1.txt adelsin_2.txt  | uniq
1
2
3
4
5
6
7
8
9
$

Jean-Pierre.

Thank you all for you responses. I'm looking at keep this answer primarily OS independant. Radoulov's answer seemed to work the best for me.

Additional question, how do I do the same thing with words and a single file?

---------- Post updated at 01:54 PM ---------- Previous update was at 01:41 PM ----------

The question is in the answer.

my %hash = map { $_, 1 } @names;
my @name_final = keys %hash;

I wish I fully understood hashes.