Part 4: Advanced text manipulation
- 1 Example data files
- 1.1 Exercise 3-1
- 2 Cut, sort, uniq
- 2.1 cut
- 2.1.1 Exercise 3-2
- 2.2 sort
- 2.2.1 Exercise 3-3
- 2.3 uniq
- 2.4 “Piping a histogram” with cut/sort/uniq -c
- 2.4.1 Exercise 3-4
- 2.5 Ensuring uniqueness of field combinations
- 2.5.1 Exercise 3-5
- 2.1 cut
- 3 Introducing awk
- 3.1.1 awk example 1
- 3.1.2 awk example 2
- 3.1.3 awk example 3
- 3.1.4 Exercise 3-6
- 3.2 A more complicated awk script
- 3.3 Parsing field-oriented text with cut and awk
- 4 Regular expressions in grep, sed and perl
- 4.1 regular expressions
- 4.2 grep pattern matching
- 4.2.1 Exercise 3-7
- 4.3 perl pattern matching
- 4.3.1 Exercise 3-8
- 4.4 sed pattern substitution
- 4.5 perl pattern substitution
- 4.5.1 Exercise 3-9
- 5 Bash control flow
- 5.1 The bash for loop
- 5.1.1 Quotes matter
- 5.1.2 Exercise 3-10
- 5.2 The if statement
- 5.3 Reading file lines with while
- 5.3.1 Exercise 3-11
- 5.1 The bash for loop
- 6 A few odds and ends
Example data files
For some of the discussions below, we'll use some files in your ~/data directory.
The ~/data/walrus_sounds.tsv file () lists the types of sounds made by several well-known walruses, and the length of each occurrence. tab-delimited fields are:
column 1 - walrus name
column 2 - sound type
column 3 - length of sound
Take a look at the first few lines of this file:
cd ~/data
head walrus_sounds.tsvThe .tsv filename extension stands for tab separated values, indicating that the field separator (the character separating fields) is tab. We can verify this using the handy hexdump alias we defined for you as discussed at Intro Unix: What is text?
cd ~/data
head walrus_sounds.tsv | hexdumpThe output looks like this, where the hexadecimal 0x09 character is a Tab.
We will also use two data files from the GSAF's (Genome Sequencing and Analysis Facility) automated processing that delivers sequencing data to customers. These files have information about customer Samples (libraries of DNA molecules to sequence on the machine), grouped into sets assigned as Jobs, and sequenced on GSAF's sequencing machines as part of sequencer Runs.