User Tools

Site Tools


wiki:2018fileglobbing

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
wiki:2018fileglobbing [2018/08/29 07:58]
david
wiki:2018fileglobbing [2018/08/29 08:13] (current)
david
Line 120: Line 120:
 <code bash> <code bash>
 $ ls gene1.*.txt $ ls gene1.*.txt
 +</​code>​
 +Produces:
 +<​code>​
 +gene1.step1.txt
 +gene1.step2.txt
 </​code>​ </​code>​
  
Line 126: Line 131:
 $ ls gene*.step1.txt $ ls gene*.step1.txt
 </​code>​ </​code>​
 +Produces:
 +<​code>​
 +gene1.step1.txt
 +gene2.step1.txt
 +gene3.step1.txt
 +</​code>​
 +
 +==== Combinations ====
 +Suppose we want all filetypes for step 1:
 +<code bash>
 +$ ls *.step1.*
 +</​code>​
 +
 +Produces:
 +<​code>​
 +gene1.step1.gff
 +gene1.step1.txt
 +gene2.step1.gff
 +gene2.step1.txt
 +gene3.step1.gff
 +gene3.step1.txt
 +</​code>​
 +
 +==== 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.
 +
 +<code bash>
 +$ ls gene1.step1.* gene3.step1.*
 +</​code>​
 +Produces:
 +<​code>​
 +gene1.step1.gff
 +gene1.step1.txt
 +gene3.step1.gff
 +gene3.step1.txt
 +</​code>​
 +
 +===== 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] ===
 +
 +<code bash>
 +$ ls gene[13].step1.*
 +</​code>​
 +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
 +</​code>​
 +
 +=== Match any one character in a range [a-z] ===
 +As above, we can use numbers instead of characters. ​
 +
 +<code bash>
 +$ ls gene[1-2].step*.gff gene[2-3].step1.txt
 +</​code>​
 +Produces:
 +<​code>​
 +gene1.step1.gff
 +gene1.step2.gff
 +gene2.step1.gff
 +gene2.step1.txt
 +gene2.step2.gff
 +gene3.step1.txt
 +</​code>​
 +
 +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.
 +
 +<code bash>
 +$ ls gene?.*
 +</​code>​
 +
 +This matches //all// filenames with a single digit gene number.
 +
 +
 +=== More examples ===
 +
 +Match files with **exactly** 3-character file extensions.
 +<code bash>
 +$ ls *.???
 +</​code>​
 +In our example, this lists all the *.txt and *.gff.
 +
 +Match files with **exactly** one character prefix.
 +<code bash>
 +$ ls ?.*
 +</​code>​
 +Since I still have a.txt b.txt and c.gff, in my directory, they are matched.
  
  
  
  
wiki/2018fileglobbing.txt ยท Last modified: 2018/08/29 08:13 by david