BASH find filenames in list that match certain "pattern."


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting BASH find filenames in list that match certain "pattern."
# 1  
Old 09-15-2010
BASH find filenames in list that match certain "pattern."

I guess by "pattern," I mean something different from how that word is defined in the Linux world. If you take $ to mean a letter (a-z) and # to mean a number (0-9), then the pattern I'm trying to match is as follows:
Code:
$$$##-####-###-###.jpg

I'd like to write a script that reads in a list of files line by line; such a list will be one where the greater number of the filenames, but by no means all of them, match that letter-number plus hyphen and extension pattern. The script finds and prints (to stdout or a text file) the names of the ones that do not conform to that pattern -- maybe there are only two (instead of three) numbers before the ".jpg"; maybe it's missing one of the 3-digit strings or the odd one is a number short; whatever the difference is, this would be the output. The ultimate purpose is to automate a renaming process (or rename the files by hand, using the generated list as a reference) to get all the files to match this letter-number-hyphen-extension sequence in their names. I hope I'm making sense here.

Can it be done in BASH? Or should I go looking elsewhere (Perl, Python, C++, etc.)?

BZT
# 2  
Old 09-15-2010
some hints for you. With reg:

Code:
[0-9] stands for digital
[a-z] stands for letter

You should be able to do it by yourself.
# 3  
Old 09-15-2010
Quote:
Originally Posted by rdcwayx
some hints for you. With reg:

Code:
[0-9] stands for digital
[a-z] stands for letter

You should be able to do it by yourself.
Don't those need defined letters and numbers to start with? And maybe there's a binary or two I've yet to become acquainted with, but I've never come across a l/Unix command "reg".

Could you give a little more detail?

BZT
# 4  
Old 09-15-2010
Quote:
Originally Posted by rdcwayx
some hints for you. With reg:

Code:
[0-9] stands for digital
[a-z] stands for letter

Quote:
Originally Posted by SilversleevesX
I've never come across a l/Unix command "reg".
rdcwayx is abbreviating "regular expression" as "reg".

rdcwayx is correctly suggesting that if you do a bit of searching around in these forums (using the search features) or research on the use of regular expressions, you will find the answer to your question quite easily.
# 5  
Old 09-15-2010
Quote:
Originally Posted by Neo
rdcwayx is abbreviating "regular expression" as "reg".

rdcwayx is correctly suggesting that if you do a bit of searching around in these forums (using the search features) or research on the use of regular expressions, you will find the answer to your question quite easily.
My thanks to you. I'll do just that.

BZT
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search file containing ps results for a match "my.cnf" and then for a second match . "ok:" and

I need to find two matches in the output from ps. I am searching with ps -ef |grep mysql for: my.cnf /bin/sh /usr/bin/mysqld_safe --defaults-file=/data/mysql/master/agis_core/etc/my.cnf after this match I want to search back and match the hostname which is x number of lines back, above the... (2 Replies)
Discussion started by: bash_in_my_head
2 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Shell Programming and Scripting

find . -path "*_nobackup*" -prune -iname "*.PDF" \( ! -name "*_nobackup.*" \)

These three finds worked as expected: $ find . -iname "*.PDF" $ find . -iname "*.PDF" \( ! -name "*_nobackup.*" \) $ find . -path "*_nobackup*" -prune -iname "*.PDF" They all returned the match: ./folder/file.pdf :b: This find returned no matches: $ find . -path "*_nobackup*" -prune... (3 Replies)
Discussion started by: wolfv
3 Replies

4. UNIX for Advanced & Expert Users

AIX - io info get from "libperfstat" not match "iostat"

Hi, everyone. I need to write a program to get io info based on libperfstat. But the "write time" of a disk is just half of the value get from iostat. I'm confused and can't explain. Help please. How I calculate "write service time per sec": In iostat: write service... (0 Replies)
Discussion started by: jackliang
0 Replies

5. UNIX for Dummies Questions & Answers

"Help with bash script" - "License Server and Patch Updates"

Hi All, I'm completely new to bash scripting and still learning my way through albeit vey slowly. I need to know where to insert my server names', my ip address numbers through out the script alas to no avail. I'm also searching on how to save .sh (bash shell) script properly.... (25 Replies)
Discussion started by: profileuser
25 Replies

6. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

7. Shell Programming and Scripting

bash: How to reuse the search result of "find"

find . -type f -print0 | xargs -0 chmod 600 find . -type f On bash, I would like to pass the search result of "find" to another command as well as to the standard output. The above code performs the same search twice -- once for "xargs -0 chmod" and another for stdout. I would like to... (5 Replies)
Discussion started by: LessNux
5 Replies

8. Shell Programming and Scripting

How can expect match the pattern "$", instead of take it as a wild card

I am writing a expect script. during the expect, i need check the out to see whether i logged in: set password "1234" spawn telnet host1 expect "login:" send "guest\n" expect "password:" send $password expect -re "#|$" puts "Logged in" But it seems that expect takes "$" as a wild... (3 Replies)
Discussion started by: sleepy_11
3 Replies

9. Shell Programming and Scripting

"find command" to find the files in the current directories but not in the "subdir"

Dear friends, please tell me how to find the files which are existing in the current directory, but it sholud not search in the sub directories.. it is like this, current directory contains file1, file2, file3, dir1, dir2 and dir1 conatins file4, file5 and dir2 contains file6,... (9 Replies)
Discussion started by: swamymns
9 Replies
Login or Register to Ask a Question