Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions episodes/04-redirection.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,14 @@ We can check the number of lines in our new file using a command called `wc`.
in a file. The FASTQ file may change over time, so given the potential for updates,
make sure your file matches your instructor's output.

As of Sept. 2020, wc gives the following output:
As of March. 2026, wc gives the following output:

```bash
$ wc bad_reads.txt
```

```output
802 1338 24012 bad_reads.txt
537 1073 23217 bad_reads.txt
```

This will tell us the number of lines, words and characters in the file. If we
Expand All @@ -226,7 +226,7 @@ $ wc -l bad_reads.txt
```

```output
802 bad_reads.txt
537 bad_reads.txt
```

::::::::::::::::::::::::::::::::::::::: challenge
Expand Down Expand Up @@ -305,7 +305,7 @@ $ wc -l bad_reads.txt
```

```output
802 bad_reads.txt
537 bad_reads.txt
```

```bash
Expand All @@ -324,35 +324,39 @@ search sequence. So our file was overwritten and is now empty.
We can avoid overwriting our files by using the command `>>`. `>>` is known as the "append redirect" and will
append new output to the end of a file, rather than overwriting it.

First, run the `grep` command for the (`SRR098026.fastq`) file.

```bash
$ grep -B1 -A2 NNNNNNNNNN SRR098026.fastq > bad_reads.txt
$ wc -l bad_reads.txt
```

```output
802 bad_reads.txt
537 bad_reads.txt
```

Then, run the `grep` command for the (`SRR097977.fastq`) file, appending the output of this command to (`bad_reads.txt`)

```bash
$ grep -B1 -A2 NNNNNNNNNN SRR097977.fastq >> bad_reads.txt
$ wc -l bad_reads.txt
```

```output
802 bad_reads.txt
537 bad_reads.txt
```

The output of our second call to `wc` shows that we have not overwritten our original data.

We can also do this with a single line of code by using a wildcard:
We can also do this with a single line of code by using a wildcard to match both `fastq` files in our directory:

```bash
$ grep -B1 -A2 NNNNNNNNNN *.fastq > bad_reads.txt
$ wc -l bad_reads.txt
```

```output
802 bad_reads.txt
537 bad_reads.txt
```

::::::::::::::::::::::::::::::::::::::::: callout
Expand Down Expand Up @@ -423,19 +427,19 @@ $ tail bad_reads.txt
```

```output
#!!!!!!!!!##########!!!!!!!!!!##!#!
@SRR098026.133 HWUSI-EAS1599_1:2:1:0:1978 length=35
ANNNNNNNNNTTCAGCGACTNNNNNNNNNNGTNGN
+SRR098026.133 HWUSI-EAS1599_1:2:1:0:1978 length=35
#!!!!!!!!!##########!!!!!!!!!!##!#!
--
--
@SRR098026.177 HWUSI-EAS1599_1:2:1:1:2025 length=35
CNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
+SRR098026.177 HWUSI-EAS1599_1:2:1:1:2025 length=35
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
```

The fifth and six lines in the output display "--" which is the default action for `grep` to separate groups of
The sixth line in the output displays "--" which is the default action for `grep` to separate groups of
lines matching the pattern, and indicate groups of lines which did not match the pattern so are not displayed.
To fix this issue, we can redirect the output of grep to a second instance of `grep` as follows.

Expand Down