Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- foo,5
- foo,7
- foo,9
- boo,5
- boo,10
- boo,10
- foo,5,7,9
- boo,5,10
- awk 'BEGIN{OFS=FS=","}!(($1,$2)in c){c[$1,$2]=1;r[$1]=r[$1] OFS $2}
- END{for(i in r){print i r[i]}}' file
- perl -F, -lane '$first{$F[0]}->{$F[1]} = (); END { print join(",", $_, sort { $a <=> $b } keys %{ $first{$_} } ) for keys %first }' < inputfile
- $ cat bla.txt
- foo,5
- foo,7
- foo,9
- boo,5
- boo,10
- boo,10
- $ { buffer="";
- while read i ; do
- key="${i%,*}" ;
- if [[ "$key" == "$oldkey" ]] ; then
- idx="${i#*,}";
- if [[ ! "$idx" == "$oidx" ]] ; then
- buffer+=",$idx" ;
- oidx="$idx";
- fi ;
- else
- test -z $buffer || echo $buffer ;
- oldkey="$key" ;
- buffer="$i" ;
- oidx="${i#*,}" ;
- fi ;
- done ; echo $buffer ; } < bla.txt
- foo,5,7,9
- boo,5,10
- $
- $ cat bla.txt
- foo,5
- foo,7
- foo,9
- boo,5
- boo,10
- boo,10
- $ qry="select c1, group_concat(c2) from bla.txt group by c1" ;
- $ q -d, "$qry" | sed -r 's/(,[^,]*)1/1/g'
- boo,5,10
- foo,5,7,9
- datamash -t ',' -s -g 1 unique 2 <infile
- boo,10,5
- foo,5,7,9
- #get sorted, unique keyword list
- cut -d, -f 1 file | sort -u |
- while read keyword ; do
- #echo keyword and sorted, unique occurrences of values
- #for keyword as output
- echo $keyword,$(grep "^$keyword," file | cut -d, -f2 |
- sort -u | tr 'n' ',' | sed 's/,$//' )
- >> sorted_file
- done
- cut -d, -f 1 file | sort -u | while read keyword ; do echo $keyword,$(grep "^$keyword," file | cut -d, -f2 | sort -u | tr 'n' ',' | sed 's/,$//' ) >> sorted_file ; done
Add Comment
Please, Sign In to add comment