3 ms·
> But that can screw with your header lines, so be careful there two. F=filename; (head -n 1 $F ; tail -n +2 $F | sort -u) | sponge $F To get counts of du
by gav 12y ago
> But that can screw with your header lines, so be careful there two.
F=filename; (head -n 1 $F ; tail -n +2 $F | sort -u) | sponge $F
To get counts of duplicates, you can use:
sort filename | uniq -c | awk '$1 != 1'
- smorrow 12y agoIf you were piping into that bracketed expression (instead of using a real file), you'd need "line", "9 read", "sh -c 'read ln; echo $ln'", or "bash -c 'read; echo $REPLY'" in place of the head since head, sed, or anything else, might use buffered I/O and bite off more than it chews. (and then a plain cat in place of the tail) "line" will compile anywhere but I only know it to be generally available on Linux. I think it's crazy that such a pipe-friendly way to extract a number of lines, and no more than that, isn't part of some standard.
- gav 12y agoIn the spirit of more options, `pee` comes with moreutils and does the trick: cat filename | pee 'head -n 1' 'tail -n +2 | sort -u'