github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/core/io/rx_doc.yaml (about) 1 - DocumentID: rx 2 Title: >+ 3 `rx` 4 CategoryID: commands 5 Summary: >- 6 Regexp pattern matching for file system objects (eg `.*\\.txt`) 7 Description: |- 8 Returns a list of files and directories that match a regexp pattern. 9 10 Output is a JSON list. 11 Usage: |- 12 ``` 13 rx pattern -> <stdout> 14 15 !rx pattern -> <stdout> 16 17 <stdin> -> rx pattern -> <stdout> 18 19 <stdin> -> !rx pattern -> <stdout> 20 ``` 21 Examples: |- 22 Inline regex file matching: 23 24 ``` 25 cat: @{ rx '.*\.txt' } 26 ``` 27 28 Writing a list of files to disk: 29 30 ``` 31 rx '.*\.go' |> filelist.txt 32 ``` 33 34 Checking if files exist: 35 36 ``` 37 if { rx somefiles.* } then { 38 # files exist 39 } 40 ``` 41 42 Checking if files do not exist: 43 44 ``` 45 !if { rx somefiles.* } then { 46 # files do not exist 47 } 48 ``` 49 50 Return all files apart from text files: 51 52 ``` 53 !g '\.txt$' 54 ``` 55 56 Filtering a file list based on regexp matches file: 57 58 ``` 59 f +f -> rx '.*\.txt' 60 ``` 61 62 Remove any regexp file matches from a file list: 63 64 ``` 65 f +f -> !rx '.*\.txt' 66 ``` 67 Detail: |- 68 ### Traversing Directories 69 70 Unlike globbing (`g`) which can traverse directories (eg `g /path/*`), `rx` is 71 only designed to match file system objects in the current working directory. 72 73 `rx` uses Go (lang)'s standard regexp engine. 74 75 ### Inverse Matches 76 77 If you want to exclude any matches based on wildcards, rather than include 78 them, then you can use the bang prefix. eg 79 80 ``` 81 » rx READ* 82 [ 83 "README.md" 84 ] 85 86 murex-dev» !rx .* 87 Error in `!rx` (1,1): No data returned. 88 ``` 89 90 ### When Used As A Method 91 92 `!rx` first looks for files that match its pattern, then it reads the file list 93 from STDIN. If STDIN contains contents that are not files then `!rx` might not 94 handle those list items correctly. This shouldn't be an issue with `rx` in its 95 normal mode because it is only looking for matches however when used as `!rx` 96 any items that are not files will leak through. 97 98 This is its designed feature and not a bug. If you wish to remove anything that 99 also isn't a file then you should first pipe into either `g *`, `rx .*`, or 100 `f +f` and then pipe that into `!rx`. 101 102 The reason for this behavior is to separate this from `!regexp` and `!match`. 103 Synonyms: 104 - rx 105 - "!rx" 106 Related: 107 - g 108 - f 109 - regexp 110 - match