0% found this document useful (0 votes)
27 views

Useful Shell Commands: Virginie Orgogozo March 2011

This document provides examples of useful shell commands for manipulating text files from the command line, including head, tail, cut, sort, and uniq. Head and tail are used to view the beginning or end of files. Cut extracts columns from files. Sort arranges lines alphabetically or numerically. Uniq removes duplicate lines. The examples demonstrate how to use these commands to extract specific lines, columns, characters from files.

Uploaded by

Santiago Salas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Useful Shell Commands: Virginie Orgogozo March 2011

This document provides examples of useful shell commands for manipulating text files from the command line, including head, tail, cut, sort, and uniq. Head and tail are used to view the beginning or end of files. Cut extracts columns from files. Sort arranges lines alphabetically or numerically. Uniq removes duplicate lines. The examples demonstrate how to use these commands to extract specific lines, columns, characters from files.

Uploaded by

Santiago Salas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
You are on page 1/ 6

Useful shell commands

head/tail, cut, sort, uniq


Virginie Orgogozo
March 2011

cat = shows the content of a file


less = shows the content of a
file

Head and tail

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

$grep ">" FPexcerpt.fta | sort


lines are sorted by alphabetical order
Options

-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

You might also like