Reputation: 586
Given a file so that in any line can be more than one word, and exists a single space between any word to other, for example:
a a a a
b b b b
c c
d d
a a a a
How can I create array so that in the cell number i
will be the line number i
, but WITHOUT DUPLICATES BETWEEN THE ELEMENTS IN THE ARRAY !
In according to the file above, we will need create this array:
Array[0]="a a a a"
, Array[1]="b b b b"
, Array[2]="c c"
, Array[3]=d d
.
(The name of the file pass to the script as argument).
I know how to create array that will contain all the lines. Something like that:
Array=()
while read line; do
Array=("${Array[@]}" "${line}")
done < $1
But how can I pass to the while read..
the sorting (and uniq) output of the file?
Upvotes: 0
Views: 36
Reputation: 13589
You should be able to use done < <(sort "$1" | uniq)
in place of done < $1
.
The <()
syntax creates a file-like object from a subshell to execute a separate set of commands.
Upvotes: 1