Check file name against convention


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Check file name against convention
# 1  
Old 03-27-2012
Check file name against convention

I need this script to check if the first 3 letters of the file name are capital.

Code:
find . -type f -name *001.dpx -exec find {} ! -name ???_???_???_v??.??????.dpx \; >> ./Bad_FileNames.txt

Currently it finds the first frame of the sequence and tests that against the naming convention. It works well but the first 3 have to be caps and they aren't consistant.

The convention is "TWH_000_000_xxx_v00.000000.dpx"

Thanks in advance.

---------- Post updated at 03:09 PM ---------- Previous update was at 03:08 PM ----------

One more thing, it would be great if it could list the owner of the file as well.
# 2  
Old 03-28-2012
You can proceed in this way
Code:
 
ls -ltr *dpx | grep ' [A-Z][A-Z][A-Z]'

# 3  
Old 03-28-2012
I don't think that will work being that the convention I need to check has capital letters, underscores, numbers, a lowercase v, more numbers, six digit file number and .dpx.

What I'm printing to the log is a report of files that don't match the naming convention.

I need the [A-Z] test but only on the first three letters of the file name.
# 4  
Old 03-29-2012
You didn't provide enough details for the first responder to answer completely. Also, your first attempt is using find - are you walking down a directory tree? or only checking in the current directory? Are you only looking for exceptions to the pattern? or searching for the filenames that correctly match?

I would start by reading the manpage for your shell - look for a section on File Name expansion or Pathname expansion. This will give you the primitive tools you can use to create a command-line that will meet your requirement... e.g.

Code:
ls -l [A-Z][A-Z][A-Z]_[0-9][0-9][0-9]_[0-9][0-9][0-9]_...etc...[0-9].dpx

if you shell's primitives are not sufficient, you can pipe the output of 'ls' through 'grep' to use more comprehensive regular expressions... e.g.

Code:
ls *.dpx | grep -v [A-Z]{3}_[0-9]{3}_[0-9]{3}_...etc...[0-9]{6}.dpx | xargs ls -l > Bad_Filenames.txt

# 5  
Old 03-30-2012
Sorry for the lack of info. I am looking for only files that DO NOT CONFORM to the standard naming convention.
The script will be run on a directory tree.
This code looks promising. How do I output only those files that do not conform?
I'm only testing frame #1 of the sequence to limit the results to a manageable output.
I'm only interested in files that do not conform. If a file conforms I want no output.

Thanks again.
# 6  
Old 03-30-2012
Running on a directory tree? - use find. Search for files that do not conform? You'll want to be careful there, as you may catch many more than you expect. I think your basic approach will be:

Code:
find /path -type f -name "*.dpx" -print | grep -v "^[A-Z]{3}"...

Between the simple inclusion search in the 'find -name' and the exclusion in the 'grep -v' you'll end up finding the inconsistent filename(s).
# 7  
Old 03-30-2012
Catching too many files is why I'm only testing *001.dpx rather than the whole sequence.
This code:
Code:
find . -type f -name *0001.dpx -print | grep -v "^[A-Z]{3}_[0-9]{3}_[0-9]{3}_cmp_v[0-9]{3}.[0-9]{6}.dpx"

catches frame 1 which DOES conform.
My original code worked well, it just wouldn't test the first 3 letters for caps. It only output the files that didn't conform. If my log is blank I knew all files were named correctly.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Change the naming convention of the output file

Hi Currently we have nmon running on our Red hat Linux server. The ouput file is now coming with the naming convention as "servername_160321_0010.nmon". The output file naming convention has to be changed as "nmon_servername_daily_2016.03.21_00.00.00" How can we do it ? Any suggestions... (10 Replies)
Discussion started by: newtoaixos
10 Replies

2. Red Hat

File System Naming Convention

Hi, I am installing a new RHEL 5 application server containing JBOSS along with other specific 3rd party applications. I know that this usually gets installed in /opt but I was thinking of installing these on a new separtate lv / file system instead. i.e. /<my_new_FS_name> rather than... (6 Replies)
Discussion started by: Duffs22
6 Replies

3. Fedora

Basic question regarding rpm naming convention.

Hi Guys, Where would i find the list of distribution codes. For example. samba-32bit-3.4.2 -1.1.3.1.x8664.rpm In above rpm file it is indicated that its release is 1.1.3.1 . The rpm is meant to be run for opensuse. Where would i get the linking of release number and distribution. ... (2 Replies)
Discussion started by: pinga123
2 Replies

4. Shell Programming and Scripting

Concatenate files to one file with naming convention

Hi , i have below files in wrk folder. file names are 1102090001.CLT 1102090003.CLT 1102100019.CLT 1102100020.CLT the above files are concatenate to one file but that concatenate file name must be same naming convention. (date +%y%m%d)and 0001 count. example : concatenate file... (9 Replies)
Discussion started by: krbala1985
9 Replies

5. Hardware

Motherboards naming convention

For the selection of motherboards, is there any naming convention in the type numbers? There is usually a brand name and sometimes a version name, but more essential details like form factor, SATA speed and maximum amount of RAM is never given. Is there a reason for that? Is there any background... (2 Replies)
Discussion started by: figaro
2 Replies

6. Solaris

Before I delete any file in Unix, How can I check no open file handle is pointing to that file?

I know how to check if any file has a unix process using a file by looking at 'lsof <fullpath/filename>' command. I think using lsof is very expensive. Also to make it accurate we need to inlcude fullpath of the file. Is there another command that can tell if a file has a truely active... (12 Replies)
Discussion started by: kchinnam
12 Replies

7. UNIX for Advanced & Expert Users

Check EOF char in Unix. OR To check file has been received completely from a remote system

Advance Thanks. (1) I would like to know any unix/Linux command to check EOF char in a file. (2) Or Any way I can check a file has been reached completely at machine B from machine A. Note that machine A ftp/scp the file to machine B at unknown time. (5 Replies)
Discussion started by: alexalex1
5 Replies

8. Shell Programming and Scripting

Naming convention script

OK, so a quick background: I am a sys admin for a 1:1 deployment in academia with Macbooks, totaling around 6,000. Macbooks get shifted around from building to building and go to and from the repair center if hardware repair is needed. Often, some machines will get moved from one building to... (8 Replies)
Discussion started by: tlarkin
8 Replies

9. UNIX Desktop Questions & Answers

Naming convention for Libraries..

Hi All, I need to know standard naming convention for Unix libraries (including all flavours of unix)..As I have gone through some sites and found out The UNIX convention for naming of libraries is lib<name>.so.<major>.<minor>.<revision> so is it statndard . also does it change... (0 Replies)
Discussion started by: rkshukla14
0 Replies

10. UNIX for Dummies Questions & Answers

Script to check for a file, check for 2hrs. then quit

I wish to seach a Dir for a specific file, once the file is found i will perform additional logic. If the file is not found within two hours, i would like to exit. Logically, I'm looking for the best way to approach this Thanks for any assistance in advance. Note: I'm using a C shell and... (2 Replies)
Discussion started by: mmarsh
2 Replies
Login or Register to Ask a Question