Created
June 18, 2010 08:05
-
-
Save leikind/443390 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat in.txt | |
1000,1030 | |
1000,1040 | |
1040,1000 | |
3000,3010 | |
3010,3000 | |
# with ruby | |
cat in.txt | ruby -n -e 'BEGIN{@a = {}}; x,y = $_.chomp.split(","); if y && x && ! y.empty? then @a[x] = y; puts $_ ; end ; END{@a.keys.each{|k| puts k + "," + k}}' | |
# with awk | |
for e in `awk 'BEGIN{RS=","}{print $1}' < in.txt | sort | uniq ` ; do echo $e,$e; done && cat in.txt | sort -u | |
# with cut | |
(for e in `cut -d, -f1 < in.txt ` ; do echo $e,$e; done && cat in.txt) | sort -u | |
# Champion: cut + xargs | |
(cut -d, -f1 < in.txt | xargs -n1 -I{} echo {},{}) && cat in.txt | sort -u |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment