Aritalab:Lecture/NGS/Unix commands/Examples
From Metabolomics.JP
< Aritalab:Lecture | NGS | Unix commands(Difference between revisions)
(Created page with "==Set Operations== We assume two sets '''A''' and '''B''' whose elements are listed line by line. *Set size: the number of elements in set A :<tt>wc -l A</tt> *Set inclusion...") |
Latest revision as of 16:23, 9 November 2015
[edit] Set Operations
We assume two sets A and B whose elements are listed line by line.
- Set size: the number of elements in set A
- wc -l A
- Set inclusion: whether an element k is in set A
- $ grep -xc 'k' A
- Set equivalence between two sets A and B
- $ diff -q <(sort A | uniq) <(sort B | uniq)
- Set union A ∪ B = C
- $ cat A B | sort | uniq > C
- Set intersection A ∩ B = C
- $ comm -12 <(sort A | uniq) <(sort B | uniq)
- The 'comm -12' command outputs shared lines only. This command can be used to find the set inclusion (whether set A is a subset of B). The following option outputs lines only in the first file (set A), i.e., no output means that A is completely included B.
- $ comm -23 <(sort A | uniq) <(sort B | uniq)
[edit] Arithmetics
- Simple arithmetic by the shell command echo "$(( ... ))" (no floating number)
- echo "$((12345 + 23456))"
- Interactive mode of Perl
- perl -E "say 123 / 1.5"