# Computational biology at CSU

### Site Tools

wiki:2018fileglobbing

# Differences

This shows you the differences between two versions of the page.

 wiki:2018fileglobbing [2018/08/29 07:58]david wiki:2018fileglobbing [2018/08/29 08:13] (current)david Both sides previous revision Previous revision 2018/08/29 08:13 david 2018/08/29 07:58 david 2018/08/29 07:33 david 2018/08/29 07:03 david created 2018/08/29 08:13 david 2018/08/29 07:58 david 2018/08/29 07:33 david 2018/08/29 07:03 david created Line 120: Line 120: \$ ls gene1.*.txt \$ ls gene1.*.txt + ​ + Produces: + <​code>​ + gene1.step1.txt + gene1.step2.txt ​ Line 126: Line 131: \$ ls gene*.step1.txt \$ ls gene*.step1.txt ​ + Produces: + <​code>​ + gene1.step1.txt + gene2.step1.txt + gene3.step1.txt + ​ + + ==== Combinations ==== + Suppose we want all filetypes for step 1: + + \$ ls *.step1.* + ​ + + Produces: + <​code>​ + gene1.step1.gff + gene1.step1.txt + gene2.step1.gff + gene2.step1.txt + gene3.step1.gff + gene3.step1.txt + ​ + + ==== Multiple patterns ==== + It's equally common to specify a number of patterns to match. Suppose we want to do the same as above for genes 1 and 3, but not 2. + + + \$ ls gene1.step1.* gene3.step1.* + ​ + Produces: + <​code>​ + gene1.step1.gff + gene1.step1.txt + gene3.step1.gff + gene3.step1.txt + ​ + + ===== Less-used wildcards and patterns ===== + + In reality, most people use the asterisk (*). But there are other constructs. The above example lists multiple patterns, but this could have been accomplished with an alternate construct: + + + === Match any one character in a set [abc] === + + + \$ ls gene[13].step1.* + ​ + This is not the number thirteen (13), but a construct to mean "match 1 or 3". It produces: + <​code>​ + gene1.step1.gff ​ + gene1.step1.txt ​ + gene3.step1.gff ​ + gene3.step1.txt + ​ + + === Match any one character in a range [a-z] === + As above, we can use numbers instead of characters. ​ + + + \$ ls gene[1-2].step*.gff gene[2-3].step1.txt + ​ + Produces: + <​code>​ + gene1.step1.gff + gene1.step2.gff + gene2.step1.gff + gene2.step1.txt + gene2.step2.gff + gene3.step1.txt + ​ + + Since our ranges only span two entries, they could have been specified as sets ''​[12]''​ and ''​[23]''​. + + === Match any single character with '?'​ === + So far, we've used the asterisk (*) to match numbers with a single digit and file extensions. If you need to restrict the length of your match, you can use the question mark to match a single character. + + + \$ ls gene?.* + ​ + + This matches //all// filenames with a single digit gene number. + + + === More examples === + + Match files with **exactly** 3-character file extensions. + + \$ ls *.??? + ​ + In our example, this lists all the *.txt and *.gff. + + Match files with **exactly** one character prefix. + + \$ ls ?.* + ​ + Since I still have a.txt b.txt and c.gff, in my directory, they are matched.