Linked Questions

94
votes
1answer
15k views

Why does my regular expression work in X but not in Y?

I wrote a regular expression which works well in a certain program (grep, sed, awk, perl, python, ruby, ksh, bash, zsh, find, emacs, vi, vim, gedit, …). But when I use it in a different program (or on ...
13
votes
3answers
5k views

Why does [a-z] asterisk match numbers?

I have 3 directories at current path. $ls a_0db_data a_clean_0db_data a_clean_data $ls a_*_data a_0db_data: a_clean_0db_data: a_clean_data: $ls a_[a-z]*_data a_clean_0db_data: a_clean_data: I ...
5
votes
4answers
4k views

Regex for checking only numbers are present after underscore not characters

I have if loop in my shell script which will check the is the table name is having any integer present this is the condition I am specifying: if [[ "$able_name" == *[0-9]* ]] Generally, the table ...
4
votes
4answers
23k views

How can I find all files in a folder that contain a match of a regular expression in the file name?

I'd like to find all of the files in my home folder on Linux (Ubuntu, in this case) that contain a match a particular regular expression. Is there a simple Unix command that I can use in order to do ...
3
votes
4answers
874 views

Fetch all filenames with specific number of characters

I want to change all filenames they have the exact length of 16 characters (digits and lower case letters). I tried [0-9a-z]{16} and [0-9a-z]\{16\} for the placeholder regX in the following snippet, ...
4
votes
3answers
1k views

Regex not matching file using `find` despite being valid [duplicate]

I am attempting to run this find command to match files with a camelcased name, with the goal being to put a space between adjacent lower and upper case letters, but it's not matching anything: find -...
1
vote
1answer
658 views

grep: use square brackets to match specific characters

So I am experimenting with the power of grep using this resources The problem I am currently encountering is that it doesn't seem to work as I intended. so I have an demo.txt file that contains foo....
4
votes
2answers
3k views

Search for files within a directory

I'm trying to search for all files given a certain string / regex value. So if I were to say search for all files that have "hello" in the name, how would I go about doing this? Ever more complex, how ...
1
vote
2answers
827 views

Using rename to remove '.orig' from file and add '_1' to basename

I'm using a script to make backups of files, and to avoid overwriting files I've used cp --backup. Which leaves me with a number of files that look like example.mov.orig and test.mov.orig. I cannot ...
2
votes
2answers
144 views

regex with find command

Hello I want to find all files in a directory ending with .h and I must use find command,I tried like this : find ~+ -name '\.h$' strangely i have .h files but the command when executed doesn't ...
1
vote
1answer
83 views

How to get the name of the source file which is used for copying using regex?

I want to copy a file whose name contains timestamp like - image-abc-20201113-1703.bin at the location /my/path/for/the/image. And I want to copy this image to a device - mydevice which is saved under ...