Guest_imported
New member
- Jan 1, 1970
- 0
Hi,
Given the following file:
a,b,c,d
a,r,f,g
j,l,m,p
z,h,q,l
(,f,%,l
s,b,f,l
I need to write a script that takes all the elements in the different fields and puts them horizontally. Each element can occur only once. This is how the outputfile should eventually look like:
(a,j,z,(,s) # these are all the elements of $1
(b,r,l,h,f) # all the different elements of $2
(c,f,m,q,%) # all the unique elements of $3
(d,g,p) # all the different of $4
So, to start with:
- look at the element in the first field;
- if element not in array, put element in array,
- else continue
- when AWK reaches the end of the file, all the different
elements should be printed horizontally, seperated by
comma's
I've added a "(" and a "%" to the example to indicate that the elements in the fields are not always letters: it cold be punctuation marks, letters, words, numbers, etc. So basically: /.*/
Can someone help me with this?
Given the following file:
a,b,c,d
a,r,f,g
j,l,m,p
z,h,q,l
(,f,%,l
s,b,f,l
I need to write a script that takes all the elements in the different fields and puts them horizontally. Each element can occur only once. This is how the outputfile should eventually look like:
(a,j,z,(,s) # these are all the elements of $1
(b,r,l,h,f) # all the different elements of $2
(c,f,m,q,%) # all the unique elements of $3
(d,g,p) # all the different of $4
So, to start with:
- look at the element in the first field;
- if element not in array, put element in array,
- else continue
- when AWK reaches the end of the file, all the different
elements should be printed horizontally, seperated by
comma's
I've added a "(" and a "%" to the example to indicate that the elements in the fields are not always letters: it cold be punctuation marks, letters, words, numbers, etc. So basically: /.*/
Can someone help me with this?