What does the # symbol in '#*/grunt-*' glob pattern mean? - gruntjs

What does the # symbol in '#*/grunt-*' glob pattern mean?
require('load-grunt-tasks')(grunt, {pattern: ['grunt-*', '#*/grunt-*']});
From load-grunt-tasks (https://github.com/sindresorhus/load-grunt-tasks) doc.

The # isn't some weird glob syntax - it's just matching directories that begin with #.
That particular glob pattern was added so that scoped NPM packages are supported - package scopes are prefixed with #.

Related

Julia 'glob' for file paths starting with forward slash

How can I use Julia's glob to extract file names of a given format, if the file paths start with forward slash, as is the case on the linux-based computing cluster I use.
For example:
using Glob
file_paths = glob("/global/cdirs/stuff/*_*_*.csv")
fails with
Glob pattern cannot be empty or start with a / character
glob does not accept absolute paths as its first argument (there's an issue about adding it). Instead, you can use the two-argument form of glob, where the second argument is the directory under which the glob should be matched. So, in this case, you can do:
using Glob
file_paths = glob("*_*_*.csv", "/global/cdirs/stuff/")
One base Julia way to get the same result would be
dir = "/global/cdirs/stuff"
filter(readdir(dir, join = true)) do f
contains(f, Regex("^$dir/.*_.*_.*\\.csv\$"))
end
but the glob way may be easier to maintain in the long run since more people are comfortable with globs than regexes.

zsh parameter expansion with asterisk as variable does not work

I am trying to remove a file extension using parameter expansion. e.g. given a filename of 123.sh, return 123.
If I store the pattern, ".*" in a variable, it does not work —${filename%$suffix} does not work.
If I specify the pattern literally, it does — ${filename%.*}
What am I doing wrong?
In the expansion ${filename%$suffix}, the value of $suffix is substituted literally. To have it be substitute as a pattern instead, you will need to use glob substitution: ${filename%$~suffix}
However, none of this is necessary for what you're trying to do. To remove the extension from a filename, you can simply use the r modifier:
❯ filename="123.sh"
❯ print $filename:r
123

What's the difference between LIKE and GLOB in SQLite?

What the difference in the following to query ?
FROM COMPANY WHERE ADDRESS GLOB '*-*';
FROM COMPANY WHERE ADDRESS LIKE '%-%';
I know unlike LIKE operator, GLOB is case sensitive. Is it the only difference ?
The documentation says:
The GLOB operator is similar to LIKE but uses the Unix file globbing syntax for its wildcards. Also, GLOB is case sensitive, unlike LIKE.
And that's it.
Other difference that GLOB you can use it as regular expression
i.e. : to select fields which end with number use GLOB '*[0-9]'
to select fields which doesn't contain any number use GLOB '[^0-9]

Difference between dir/**/* and dir/*/* in Unix glob pattern?

It seems that the output are the same when I echoed it.
I also tested other commands such as open, but the results from both are the same.
In traditional sh-style pattern matching, * matches zero or more characters in a component of the file name, so there is no difference between *, **, and ***, either on its own or as part of a larger pattern.
However, there are globbing syntaxes that assign a distinct meaning to **. Pattern matching implemented by the Z shell, for example, expands x/**/y to all file names beginning with x/ and ending in /y regardless of how many directories are in between, thus matching all of x/y, x/subdir/y, x/subdir1/subdir2/y, etc. This syntax was later implemented by bash, although only enabled when the globstar configuration option is set by the user.

using R to copy files

As part of a larger task performed in R run under windows, I would like to copy selected files between directories. Is it possible to give within R a command like cp patha/filea*.csv pathb (notice the wildcard, for extra spice)?
I don't think there is a direct way (shy of shelling-out), but something like the following usually works for me.
flist <- list.files("patha", "^filea.+[.]csv$", full.names = TRUE)
file.copy(flist, "pathb")
Notes:
I purposely decomposed in two steps, they can be combined.
See the regular expression: R uses true regex, and also separates the file pattern from the path, in two separate arguments.
note the ^ and $ (beg/end of string) in the regex -- this is a common gotcha, as these are implicit to wildcard-type patterns, but required with regexes (lest some file names which match the wildcard pattern but also start and/or end with additional text be selected as well).
In the Windows world, people will typically add the ignore.case = TRUE argument to list.files, in order to emulate the fact that directory searches are case insensitive with this OS.
R's glob2rx() function provides a convenient way to convert wildcard patterns to regular expressions. For example fpattern = glob2rx('filea*.csv') returns a different but equivalent regex.
You can
use system() to fire off a command as if it was on shell, incl globbing
use list.files() aka dir() to do the globbing / reg.exp matching yourself and the copy the files individually
use file.copy on individual files as shown in mjv's answer

Resources