Skip to content

Instantly share code, notes, and snippets.

@antoinecourtin
Created February 25, 2015 16:57
Show Gist options
  • Save antoinecourtin/de864076e9564b3f08ac to your computer and use it in GitHub Desktop.
Save antoinecourtin/de864076e9564b3f08ac to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
dir=antoine
mkdir -p $dir # creation repertoire
(echo "antoine courtin pierre"
echo "antoine courtin toto"
echo "b d e") > $dir/test
cut -f1-2 -d' ' $dir/test |
sort |
uniq -c |
sed -e 's#^ *##' > $dir/test.count
cat $dir/test.count |
while read line
do
var1=`echo $line | cut -f2- -d' '`
list=`grep "$var1" $dir/test \
| tr '\n' ' ' \
| sed -e 's# $#\n#' \
-e "s#$var1##g" \
| tr -s ' ' \
| sed -e 's#^ ##' \
| tr ' ' ','`
echo "$line \"$list\""
done | tr ' ' ',' > $dir/test.final
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment