Sponsored Content
Top Forums Shell Programming and Scripting Finding files in directory with similar names Post 302898019 by neutronscott on Thursday 17th of April 2014 05:18:05 PM
Old 04-17-2014
Code:
#!/bin/bash

declare -A max=()

# first, find highest.
for f in *REV*.PDF; do
        base=${f%_REV*}
        rev=${f##*_REV}
        rev=${rev%.PDF}

        [[ -z "${max[$base]}" ]] && max["$base"]=$rev
        (( rev > "${max[$base]}" )) && max["$base"]=$rev
done

for prefix in "${!max[@]}"; do
        for f in "$prefix"*; do
                rev=${f##*_REV}
                rev=${rev%.PDF}
                if (( rev < "${max[$prefix]}" )); then
                        echo mv "$f" /someplace/for/old/files
                fi
        done
done

Code:
mute@thedoctor:~/temp/kamezero$ touch {ONE,TWO,THREE}_REV{1..5}.PDF
mute@thedoctor:~/temp/kamezero$ ./script
mv THREE_REV1.PDF /someplace/for/old/files
mv THREE_REV2.PDF /someplace/for/old/files
mv THREE_REV3.PDF /someplace/for/old/files
mv THREE_REV4.PDF /someplace/for/old/files
mv ONE_REV1.PDF /someplace/for/old/files
mv ONE_REV2.PDF /someplace/for/old/files
mv ONE_REV3.PDF /someplace/for/old/files
mv ONE_REV4.PDF /someplace/for/old/files
mv TWO_REV1.PDF /someplace/for/old/files
mv TWO_REV2.PDF /someplace/for/old/files
mv TWO_REV3.PDF /someplace/for/old/files
mv TWO_REV4.PDF /someplace/for/old/files

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Finding Names in multiple files

What's the best way to see if a common name exists in two separate files? (3 Replies)
Discussion started by: Rally_Point
3 Replies

2. UNIX for Dummies Questions & Answers

Finding names in multiple files - second attempt

I couldn't find the original thread that I created and since I didn't get a definitive answer, I figured I'd try again. Maybe this time I can describe what I want a little better. I've got two files, each with thousands of names all separated by new line. I want to know if 'name in file1'... (2 Replies)
Discussion started by: Rally_Point
2 Replies

3. Shell Programming and Scripting

parsing file names and then grouping similar files

Hello Friends, I have .tar files which exists under different directories after the below code is run: find . -name "*" -type f -print | grep .tar > tmp.txt cat tmp.txt ./dir1/subdir1/subdir2/database-db1_28112009.tar ./dir2/subdir3/database-db2_28112009.tar... (2 Replies)
Discussion started by: EAGL€
2 Replies

4. Shell Programming and Scripting

Script to move files with similar names to folder

I have in directory /media/AUDIO/WAVE many .mp3 files with names like: my filename_01of02.mp3 my filename_02of02.mp3 Your File_01of06.mp3 Your File_02of06.mp3 etc.... In the same directory, /media/AUDIO/WAVE, I have many folders with names like 9780743579490 9780743579491 etc.. Inside... (7 Replies)
Discussion started by: glev2005
7 Replies

5. Shell Programming and Scripting

concatenating similar files in a directory

Hi, I am new in unix. I have below requirement: I have two files at the same directory location File1.txt and File2.txt (just an example, real scenario we might have File2 and File3 OR File6 and File7....) File1.txt has : header1 record1 trailer1 File2.txt has: header2 record2... (4 Replies)
Discussion started by: Deepak62828r
4 Replies

6. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

7. UNIX for Dummies Questions & Answers

finding overlapping names in different txt files

Dear Gurus, I have 57 tab-delimited different text files, each one containing entries in 3 columns. The first column in each file contains names of objects. Some names are present in more than one file. I would like to find those names and store them in a separate text file, preferably with a... (6 Replies)
Discussion started by: Unilearn
6 Replies

8. Shell Programming and Scripting

Merging two columns from two files with similar names into a loop

I have two files like this: fileA.net A B C fileA.dat 1 2 3 and I want the output output_expected A 1 B 2 C 3 I know that the easier way is to do a paste fileA.net fileA.dat, but the problem is that I have 10,000 couple of files (fileB.net with fileB.dat; fileC.net with... (3 Replies)
Discussion started by: valente
3 Replies

9. UNIX for Dummies Questions & Answers

Finding similar strings between two files

Hi, I have a file1 like this: ABAT ABCA1 ABCC1 ABCC5 ABCC8 ABCE1 ABHD2 ABL1 CAMTA1 ACBD3 ACCN1 And I have a second file like this: chr19 46118590 46119564 MACS_peak_1499 3100.00 chr19 46122009 46148405 CYP2B7P1 -2445 chr1 7430312 7430990... (7 Replies)
Discussion started by: a_bahreini
7 Replies

10. Shell Programming and Scripting

Directory containing files,Print names of the files in the directory that are exactly same content.

Given a directory containing say a few thousand files, please output a list of all the names of the files in the directory that are exactly the same, i.e. have the same contents. func(a_directory_name) output -> {“matches”: , ... ]} e.g. func(“/home/my/files”) where the directory... (7 Replies)
Discussion started by: anuragpgtgerman
7 Replies
PDF::API2::Basic::PDF::Dict(3pm)			User Contributed Perl Documentation			  PDF::API2::Basic::PDF::Dict(3pm)

NAME
PDF::API2::Basic::PDF::Dict - PDF Dictionaries and Streams. Inherits from PDF::Objind INSTANCE VARIABLES
There are various special instance variables which are used to look after, particularly, streams. Each begins with a space: stream Holds the stream contents for output streamfile Holds the stream contents in an external file rather than in memory. This is not the same as a PDF file stream. The data is stored in its unfiltered form. streamloc If both ' stream' and ' streamfile' are empty, this indicates where in the source PDF the stream starts. METHODS
$d->outobjdeep($fh) Outputs the contents of the dictionary to a PDF file. This is a recursive call. It also outputs a stream if the dictionary has a stream element. If this occurs then this method will calculate the length of the stream and insert it into the stream's dictionary. $d->read_stream($force_memory) Reads in a stream from a PDF file. If the stream is greater than "PDF::Dict::mincache" (defaults to 32768) bytes to be stored, then the default action is to create a file for it somewhere and to use that file as a data cache. If $force_memory is set, this caching will not occur and the data will all be stored in the $self->{' stream'} variable. $d->val Returns the dictionary, which is itself. perl v5.14.2 2014-03-09 PDF::API2::Basic::PDF::Dict(3pm)
All times are GMT -4. The time now is 08:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy