...
- -p tells perl to print its substitution results
- -e introduces the perl script (always encode it in single quotes to protect it from shell evaluation)
- ~s is the perl pattern substitution operator
- forward slashes ("/ / /") enclose the regex search pattern and the replacement text
- parentheses ( ) enclosing a pattern "capture" text matching the pattern in a built-in positional variable
- $1 for the 1st captured text, $2 for the 2nd captured text, etc.
Handling multiple FASTQ files example
...
Here's a one-liner that isolates just the unique sample names, where there are 2 files for each sample name:
Code Block | ||
---|---|---|
| ||
find /stor/work/CCBB_Workshops_1/bash_scripting/fastq -name "*.fastq.gz" \
| perl -pe 's|.*/||' | perl -pe 's/_S\d.*//' | sort | uniq
|
But what if we want to manipulate each of the 4 FASTQ files? For example, count the number of lines in each one. Let's start with a for loop to get their full paths, and just the FASTQ file names without the _R1_001.fastq.gz suffix:
...