Find files that do not match specific patterns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find files that do not match specific patterns
# 15  
Old 01-26-2011
Im afraid, that output has no files that match your criteria - maybe the typo of ".jpp" in your original request should have been ".jpg" ?
# 16  
Old 01-26-2011
@citaylor - thanks very much for your help - that worked like a charm! Smilie

Now that I have a list of these files is there someway I could create a pairing file which I could execute and have all the files renamed as would specified by the pairing file?
# 17  
Old 01-26-2011
certainly...could you describe what you want renamed from what to what ?
# 18  
Old 01-26-2011
Quote:
Originally Posted by SandmanCL
Not too elegant, but this perl example should print a list of files that don't match your patterns:

Code:
#!/usr/local/bin/perl

$\ = "\n";

@files = split/\n/,`ls /path/to/your/dir`;
foreach (@files) {
  if (!/^...-..-....\.jpp|^...-..-....-.mi\.jpg/) {
    print;
  }
}

this is bad. do not shell out unless you absolutely have to. In Perl , you can use
Code:
while (<*>){
   ....
}

to display files

---------- Post updated at 08:38 AM ---------- Previous update was at 08:35 AM ----------

Quote:
Originally Posted by SandmanCL
Try this

Code:
#!/bin/sh

for file in `ls /path/to/yourdir`; do
  if [ -z `"echo $file | egrep '^...-..-....\.jpp|^...-..-....-.mi\.jpg'"` ]; then
    echo $file
  fi
done

another bad example. Don't use ls to parse files. use the shell
Code:
for file in *
do
  ....
done

# 19  
Old 01-26-2011
@citaylor - well i would ideally like to be able to create a flat file in the form of:

[name of file to rename] | [new file name]

and then execute some sort of script that will apply the renaming to the files that exist in a specific folder.

again many thanks for your help
# 20  
Old 01-26-2011
Is there a predefined list of these renames, or is there an algorithm we could use to know what to rename the files to ? The latter is easier, but the former isnt difficult either...
# 21  
Old 01-27-2011
@citaylor - there is a predifined list which I would like to use - an alogorithm would be nice to use however as many of these files have been in correctly named by hand it would be very dificult to create an algorithm that would be able to do the matching automatically
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Match patterns between two files and extract certain range of strings

Hi, I need help to match patterns from between two different files and extract region of strings. inputfile1.fa >l-WR24-1:1 GCCGGCGTCGCGGTTGCTCGCGCTCTGGGCGCTGGCGGCTGTGGCTCTACCCGGCTCCGG GGCGGAGGGCGACGGCGGGTGGTGAGCGGCCCGGGAGGGGCCGGGCGGTGGGGTCACGTG... (4 Replies)
Discussion started by: bunny_merah19
4 Replies

2. Shell Programming and Scripting

Bash - Find files excluding file patterns and subfolder patterns

Hello. For a given folder, I want to select any files find $PATH1 -f \( -name "*" but omit any files like pattern name ! -iname "*.jpg" ! -iname "*.xsession*" ..... \) and also omit any subfolder like pattern name -type d \( -name "/etc/gconf/gconf.*" -o -name "*cache*" -o -name "*Cache*" -o... (2 Replies)
Discussion started by: jcdole
2 Replies

3. Shell Programming and Scripting

awk to print match or non-match and select fields/patterns for non-matches

In the awk below I am trying to output those lines that Match between file1 and file2, those Missing in file1, and those missing in file2. Using each $1,$2,$4,$5 value as a key to match on, that is if those 4 fields are found in both files the match, but if those 4 fields are not found then missing... (0 Replies)
Discussion started by: cmccabe
0 Replies

4. Shell Programming and Scripting

Insert a newline after match in files of specific name under some subdirectories?

Hi I'd like to add the newline: \tuser: nobody", or "<TAB>user: nobody to all files named: docker-compose.ymlin subfolders of pwd with names beginning with 10-20. Within these files, I'd like to find the line (there'll only be one) containing: command: celery workerNOTE: As far as... (2 Replies)
Discussion started by: duncanbetts
2 Replies

5. Shell Programming and Scripting

Find matched patterns in multiple files

Hi, I need help to find matched patterns in 30 files residing in a folder simultaneously. All these files only contain 1 column. For example, File1 Gr_1 st-e34ss-11dd bt-wwd-fewq pt-wq02-ddpk pw-xsw17-aqpp Gr_2 srq-wy09-yyd9 sqq-fdfs-ffs9 Gr_3 etas-qqa-dfw ddw-ppls-qqw... (10 Replies)
Discussion started by: redse171
10 Replies

6. UNIX Desktop Questions & Answers

Combining files with specific patterns of naming in a directory

Greetings Unix exports, I am facing some problems in combining files with different name patterns with a directory and I would appreciate if you can help me I have more than 1000 files but they follow a specific pattern of naming. e.g. 64Xtest01.txt They are divided into two sets of test and... (9 Replies)
Discussion started by: A-V
9 Replies

7. UNIX for Dummies Questions & Answers

Find diff between two patterns in two files and append

Hi, I'm a newbie at programming in Unix, and I seem to have a task that is greater than I can handle. Trying to learn awk by the way (but in the end, i just need something that works). My goal is to compare two files and output the difference between the two. I've been reading, and I think I... (5 Replies)
Discussion started by: legato22
5 Replies

8. UNIX for Dummies Questions & Answers

move files that match specific conditions

Hi all, I'm new to this forum and bash scripting. I have the following problem, I need to copy some files (from one dir. to another) whose first 5 numbers (subjects' ID) match the directory names. Here a shortened version of what I'm trying to do: names=(32983_f 35416_f 43579_f) # these are... (6 Replies)
Discussion started by: ada1983
6 Replies

9. Shell Programming and Scripting

Using AWK to match CSV files with duplicate patterns

Dear awk users, I am trying to use awk to match records across two moderately large CSV files. File1 is a pattern file with 173,200 lines, many of which are repeated. The order in which these lines are displayed is important, and I would like to preserve it. File2 is a data file with 456,000... (3 Replies)
Discussion started by: isuewing
3 Replies

10. Shell Programming and Scripting

script to match patterns in 2 different files.

I am new to shell scripting and need some help. I googled, but couldn't find a similar scenario. Basically, I need to rename a datafile. This is the scenario - I have a file, readonly.txt that has 2 columns - file# and name. I have another file,missing_files.txt that has id and name. Both the... (3 Replies)
Discussion started by: mathews
3 Replies
Login or Register to Ask a Question