All Questions
Tagged with pattern-matching shell
9 questions
0
votes
1
answer
118
views
Bash: Difference between "Pattern Matching" and "Filename Expansion" in the context of parameter expansions that do matching
Edit: Question ansewered by Gordon Davisson's comment
I was reading the GNU Bash manual, and I noticed that there are basically three types of "Parameter expansion" that do pattern matching:
...
0
votes
2
answers
60
views
How to combine files from incrementing directories into one directory
I have a directory structure that follows this kind of pattern:
- Dir 01 (Disc 1) \
- Dir 01 (Disc 1).iso
- Dir 01 (Disc 2) \
- Dir 01 (Disc 2).iso
- Dir 01 (Disc 3) \
- Dir 01 (Disc 3).iso
- ...
4
votes
3
answers
3k
views
Is there a way to make find use shell's extglob shell option?
In short, I instinctively wrote a command like this to find the two files prefix.ext and prefix_suffix.ext down a hierarchy
find /some/path -type f -name 'prefix?(_suffix).zip'
but it doesn't work.
...
0
votes
1
answer
235
views
How to replace a hash pattern inside file and directory names
I've just backed up the notes I have in Notion, and they use hashcodes in the notes names to make them unique apparently.
For example, this is might be a note-folder with some notes:
Archive ...
2
votes
1
answer
3k
views
Why does using double brackets "[[" to check if wildcard matched files exists fail, while single brackets "[" work?
Let's say I generate a two directories with text files in each like so
mkdir "Directory1"
mkdir "Directory2"
touch "Directory1/fileclass1_"{1..5}".txt"
touch &...
0
votes
1
answer
233
views
find a file based on date mentioned in parameter
I have a requirement to find a file based on date provided in the parameter.
For example, I have these files:
XYZ.ABC.M.20200615180200.batch
XYZ.ABC.M.20200616180200.batch
XYZ.ABC.M.20200617180200....
5
votes
9
answers
6k
views
How can I make sure a string contains at least one uppercase letter, one lowercase letter, one number and one punctuation character?
This is what I'm using now to get the job done:
#!/bin/sh --
string='Aa1!z'
if ! printf '%s\n' "$string" | LC_ALL=C grep -q '[[:upper:]]' || \
! printf '%s\n' "$string" | LC_ALL=C grep -q '[[:...
8
votes
4
answers
4k
views
Write a function that checks if a string starts with or contains something
I want to write a function that checks if a given variable, say, var, starts with any of the words in a given list of strings. This list won't change.
To instantiate, let's pretend that I want to ...
3
votes
0
answers
47
views
Should I set the locale to `C` when matching a range of numbers?
If I wanted to search for lines in a file that contain a or b or c or d I would run
LC_COLLATE=C grep -E '[a-d]' file_to_search
or
LC_ALL=C grep -E '[a-d]' file_to_search
If I fail to set the locale ...