Useful Shell Commands: Virginie Orgogozo March 2011
Useful Shell Commands: Virginie Orgogozo March 2011
cd pcfb/examples/
$head ctd.txt
shows the first 10 lines
$head -n 2 *.pdb
shows the first 2 lines
$history | tail -n 15
shows the 15 most recent items in your command history
$tail -n +2 Thalas*.txt
shows from the second line to the end
$head -n -1 Thalas*.txt
shows from the second line to the 10th line
Cut
cd pcfb/examples/
$cut -f 1,3 Thal*.txt
returns columns 1 and 3 delimited by tabs
$cut -f 1-3 Thal*.txt
returns columns 1 to 3 delimited by tabs
$cut -c 16-20,30 Thal*.txt
returns characters 16 to 20 and 30 from each line
$grep ">" FPexamples.fta | cut -c 2-11
prints out the gene names
$head ctd.txt | cut -f 5,7 -d ","
returns columns 5 and 7. These are delimited by , in the original
file and in the output.
Be careful when space is used between columns because there
are sometimes two spaces instead of one.
Sort
-n
sorts by numerical value rather than alphabetically
-f
Make all lines uppercase before sorting
-r
sorts in reverse order
-k 3
sorts lines based on column 3 , with columns delimited by space or tab
$head Thal.txt | sort -k 2
-t ","
uses commas for delimiters
-u
returns a unique representative of repeated items
The ASCII
list
Uniq
Removes identical lines that are in immediate succession and keeps a
single line.
Options
-c
counts the number of occurrence of each unique line and write it before
each unique line
$cut -c 12-21 ctd.txt | uniq -c
-f 4
ignores the first 4 fields (columns delimited by any number of spaces) in
determining uniqueness
-i
ignore case when determining uniqueness