Main Page | Report this Page
 
   
Linux Forum Index  »  General Linux Discussion  »  find script?...
Page 1 of 1    
Author Message
P1...
Posted: Tue Aug 05, 2008 6:30 pm
Guest
I'm in need of script that would allow me to find the following but
I've never scripted anything. Hoping to get some help as I just don't
have time to learn scripting just for this particular task, although
it's definitely something I want to put on my todo list...

Find all subfolders with a file.ext1 and file.ext2 but only where the
letter case of "file" is different. There are three possible ways the
name can be spelled: file, File and FILE.

So a subfolder containing both file.ext1 and File.ext2 would be found
since the case is different, but a subfolder containing FILE.ext1 and
FILE.ext2 would not, since the case matches.

Hope that makes sense...

Thanks,
Pete.
Stephane CHAZELAS...
Posted: Tue Aug 05, 2008 10:52 pm
Guest
2008-08-05, 16:30(-07), P1:
Quote:
I'm in need of script that would allow me to find the following but
I've never scripted anything. Hoping to get some help as I just don't
have time to learn scripting just for this particular task, although
it's definitely something I want to put on my todo list...

Find all subfolders with a file.ext1 and file.ext2 but only where the
letter case of "file" is different. There are three possible ways the
name can be spelled: file, File and FILE.

So a subfolder containing both file.ext1 and File.ext2 would be found
since the case is different, but a subfolder containing FILE.ext1 and
FILE.ext2 would not, since the case matches.
[...]


With zsh:

setopt extendedglob

for d (**(D/)) {
ext1=($d/((#i)file).ext1(:r:t[1]))
ext2=($d/((#i)file).ext2(:r:t[1]))
(($#ext1 && $#ext2)) || continue

[[ "$ext1" = "$ext2" ]] ||
print -r -- "$d"
}

POSIXly:

find . -type d -exec sh -c '
dir=$1
set -- "$dir"/[fF][iI][lL][eE].ext1
ext1=$1
[ "$ext1" != "$dir/[fF][iI][lL][eE].ext1" ] || exit
set -- "$dir"/[fF][iI][lL][eE].ext2
ext2=$1
[ "$ext2" != "$dir/[fF][iI][lL][eE].ext2" ] || exit
ext1=${ext1##*/}
ext1=${ext1%.*}
ext2=${ext2##*/}
ext2=${ext2%.*}
[ "$ext1" != "$ext2" ]' {} {} \; -print

--
Stéphane
Auric__...
Posted: Wed Aug 06, 2008 6:16 am
Guest
On Tue, 05 Aug 2008 23:30:23 GMT, P1 wrote:

Quote:
I'm in need of script that would allow me to find the following but
I've never scripted anything. Hoping to get some help as I just don't
have time to learn scripting just for this particular task, although
it's definitely something I want to put on my todo list...

Find all subfolders with a file.ext1 and file.ext2 but only where the
letter case of "file" is different. There are three possible ways the
name can be spelled: file, File and FILE.

So a subfolder containing both file.ext1 and File.ext2 would be found
since the case is different, but a subfolder containing FILE.ext1 and
FILE.ext2 would not, since the case matches.

That sounds very much like some sort of homework.

--
- I'm writing an episode of "The Outer Limits".
- You *are* an episode of "The Outer Limits".
P1...
Posted: Wed Aug 06, 2008 3:24 pm
Guest
You're the second person that stated that this sounds like homework.
Maybe it does, I've never taken a Linux class, been a Windows admin
for many years, just starting to scratch the surface of Linux. I
changed the filenames in my description, but the problem is actually a
real-world one. I migrated a proprietary email system (Gordano GMS)
from Windows to Linux a couple of weeks ago. Most accounts work fine,
but a few hundred don't and I found that they don't because the
INBOX.MBX file case doesn't match the INBOX.IDX file case, so the
system can't find the index for the mailbox file and hence shows the
mailbox as empty. I need to find all directories where these two
files have a different case so that I can fix that problem. In
Windows, this didn't matter because there is no case sensitivity, but
obviously in Linux this broke the mailbox. Gordano support is trying
to figure out how to fix this programmatically also, but they're slow
as hell so I was trying a different avenue...

Pete.

On Wed, 6 Aug 2008 16:16:17 +0000 (UTC), "Auric__"
<not.my.real at (no spam) email.address> wrote:

Quote:
On Tue, 05 Aug 2008 23:30:23 GMT, P1 wrote:

I'm in need of script that would allow me to find the following but
I've never scripted anything. Hoping to get some help as I just don't
have time to learn scripting just for this particular task, although
it's definitely something I want to put on my todo list...

Find all subfolders with a file.ext1 and file.ext2 but only where the
letter case of "file" is different. There are three possible ways the
name can be spelled: file, File and FILE.

So a subfolder containing both file.ext1 and File.ext2 would be found
since the case is different, but a subfolder containing FILE.ext1 and
FILE.ext2 would not, since the case matches.

That sounds very much like some sort of homework.
David W. Hodgins...
Posted: Wed Aug 06, 2008 4:10 pm
Guest
On Wed, 06 Aug 2008 16:24:24 -0400, P1 <p1 at (no spam) eagency.com> wrote:

Quote:
changed the filenames in my description, but the problem is actually a
real-world one. I migrated a proprietary email system (Gordano GMS)
from Windows to Linux a couple of weeks ago. Most accounts work fine,
but a few hundred don't and I found that they don't because the
INBOX.MBX file case doesn't match the INBOX.IDX file case, so the

#!/bin/bash
PathStart="/home/dave/test/" # Root of directories to be searched
for PathCurrent in $(find $PathStart -type d) ; do
IFS=$'\n'
cd "$PathCurrent"
OutputFind=( `find . -maxdepth 1 -type f ` ) # Put file names into array
unset IFS
FilesNumber=${#OutputFind[ at (no spam) ]}
for ((FileIndexCurrent=0; FileIndexCurrent < FilesNumber; FileIndexCurrent ++)); do
FileNameCurrent="${OutputFind[$FileIndexCurrent]:2}" # strip leading ./
FileNameCurrentWithoutExtenstion="${FileNameCurrent%%[\.]*}" # strip everything after first period
FileNameCurrentWithoutExtenstionLowerCase=`echo $FileNameCurrentWithoutExtenstion | tr A-Z a-z`
for ((FileIndexNext=FileIndexCurrent; FileIndexNext < FilesNumber; FileIndexNext ++)); do
FileNameCheck="${OutputFind[$FileIndexNext]:2}"
FileNameCheckWithoutExtenstion="${FileNameCheck%%[\.]*}"
FileNameCheckWithoutExtenstionLowerCase=`echo $FileNameCheckWithoutExtenstion | tr A-Z a-z`
if [[ ( $FileNameCurrentWithoutExtenstionLowerCase == $FileNameCheckWithoutExtenstionLowerCase ) && \
( $FileNameCurrentWithoutExtenstion != $FileNameCheckWithoutExtenstion )]] ; then
echo "Case mismatch found for $FileNameCurrent in $PathCurrent"
fi
done
done
done

Regards, Dave Hodgins

--
Change nomail.afraid.org to ody.ca to reply by email.
(nomail.afraid.org has been set up specifically for
use in usenet. Feel free to use it yourself.)
David W. Hodgins...
Posted: Wed Aug 06, 2008 4:26 pm
Guest
On Wed, 06 Aug 2008 16:24:24 -0400, P1 <p1 at (no spam) eagency.com> wrote:

Quote:
mailbox as empty. I need to find all directories where these two
files have a different case so that I can fix that problem. In

Just in case work wrap, or format flowed messes up the script, I've uploaded
a copy to http://www.ody.ca/~dwhodgins/findmix

Regards, Dave Hodgins

--
Change nomail.afraid.org to ody.ca to reply by email.
(nomail.afraid.org has been set up specifically for
use in usenet. Feel free to use it yourself.)
Unruh...
Posted: Wed Aug 06, 2008 5:03 pm
Guest
P1 <p1 at (no spam) eagency.com> writes:

Quote:
You're the second person that stated that this sounds like homework.
Maybe it does, I've never taken a Linux class, been a Windows admin
for many years, just starting to scratch the surface of Linux. I
changed the filenames in my description, but the problem is actually a
real-world one. I migrated a proprietary email system (Gordano GMS)
from Windows to Linux a couple of weeks ago. Most accounts work fine,
but a few hundred don't and I found that they don't because the
INBOX.MBX file case doesn't match the INBOX.IDX file case, so the

So, why not change them all to the same case for all users, and have
everything be stadard.

for i in `find . -iname inbox.mbx`
do
j=`dirname $i`
mv $i ${j}/inbox.mbx
done

and then the same for inbox.idx

Quote:
system can't find the index for the mailbox file and hence shows the
mailbox as empty. I need to find all directories where these two
files have a different case so that I can fix that problem. In
Windows, this didn't matter because there is no case sensitivity, but
obviously in Linux this broke the mailbox. Gordano support is trying
to figure out how to fix this programmatically also, but they're slow
as hell so I was trying a different avenue...

Pete.

On Wed, 6 Aug 2008 16:16:17 +0000 (UTC), "Auric__"
not.my.real at (no spam) email.address> wrote:

On Tue, 05 Aug 2008 23:30:23 GMT, P1 wrote:

I'm in need of script that would allow me to find the following but
I've never scripted anything. Hoping to get some help as I just don't
have time to learn scripting just for this particular task, although
it's definitely something I want to put on my todo list...

Find all subfolders with a file.ext1 and file.ext2 but only where the
letter case of "file" is different. There are three possible ways the
name can be spelled: file, File and FILE.

So a subfolder containing both file.ext1 and File.ext2 would be found
since the case is different, but a subfolder containing FILE.ext1 and
FILE.ext2 would not, since the case matches.

That sounds very much like some sort of homework.
P1...
Posted: Wed Aug 06, 2008 6:20 pm
Guest
Thought about that too, but unfortunately, there's a config file or
something somewhere that tells the system how the file name is
spelled, and it's not the same for all users, so I can't standardize
it, unless Gordano rewrites their code to ignore case or we can find
the config file and modify the names there. I don't even know if it
is a config file or if it's hard-coded.

Pete

On Wed, 06 Aug 2008 22:03:08 GMT, Unruh <unruh-spam at (no spam) physics.ubc.ca>
wrote:

Quote:
P1 <p1 at (no spam) eagency.com> writes:

You're the second person that stated that this sounds like homework.
Maybe it does, I've never taken a Linux class, been a Windows admin
for many years, just starting to scratch the surface of Linux. I
changed the filenames in my description, but the problem is actually a
real-world one. I migrated a proprietary email system (Gordano GMS)
from Windows to Linux a couple of weeks ago. Most accounts work fine,
but a few hundred don't and I found that they don't because the
INBOX.MBX file case doesn't match the INBOX.IDX file case, so the

So, why not change them all to the same case for all users, and have
everything be stadard.

for i in `find . -iname inbox.mbx`
do
j=`dirname $i`
mv $i ${j}/inbox.mbx
done

and then the same for inbox.idx

system can't find the index for the mailbox file and hence shows the
mailbox as empty. I need to find all directories where these two
files have a different case so that I can fix that problem. In
Windows, this didn't matter because there is no case sensitivity, but
obviously in Linux this broke the mailbox. Gordano support is trying
to figure out how to fix this programmatically also, but they're slow
as hell so I was trying a different avenue...

Pete.

On Wed, 6 Aug 2008 16:16:17 +0000 (UTC), "Auric__"
not.my.real at (no spam) email.address> wrote:

On Tue, 05 Aug 2008 23:30:23 GMT, P1 wrote:

I'm in need of script that would allow me to find the following but
I've never scripted anything. Hoping to get some help as I just don't
have time to learn scripting just for this particular task, although
it's definitely something I want to put on my todo list...

Find all subfolders with a file.ext1 and file.ext2 but only where the
letter case of "file" is different. There are three possible ways the
name can be spelled: file, File and FILE.

So a subfolder containing both file.ext1 and File.ext2 would be found
since the case is different, but a subfolder containing FILE.ext1 and
FILE.ext2 would not, since the case matches.

That sounds very much like some sort of homework.
Unruh...
Posted: Wed Aug 06, 2008 7:26 pm
Guest
P1 <p1 at (no spam) eagency.com> writes:

Quote:
Thought about that too, but unfortunately, there's a config file or
something somewhere that tells the system how the file name is
spelled, and it's not the same for all users, so I can't standardize
it, unless Gordano rewrites their code to ignore case or we can find
the config file and modify the names there. I don't even know if it
is a config file or if it's hard-coded.

If it is hard coded then it should be the same for all. You say they are
not the same for all.
You are left with the problem that if the two names disagree, then which is
the one that determines what the common name should be?

You can always. strip off the suffix, and attach the other one if necessary

for i in `find . -iname inbox.imx`
do
j=`dirname $i`
k=`basename $i .MBX`
q=`find $j --maxdepth=1 -iname ${k}.IDX`
if [ -f $q ]; then
mv $q ${j}.IDX
fi
done


This would name the IDX file the same as the MBX file
Alternatively dump that idiotic mail system and go with something useful.

Alternatively if you just want to list the directories where they differ

for i in `find . -iname inbox.MBX`
do
j=`dirname $i`
k=`basename $i .MBX`
l=`find $j -iname inbox.IDX`
if [ "`basename $l .IDX`" != "$k" ]; then
echo $k
fi
done


Quote:
Pete

On Wed, 06 Aug 2008 22:03:08 GMT, Unruh <unruh-spam at (no spam) physics.ubc.ca
wrote:

P1 <p1 at (no spam) eagency.com> writes:

You're the second person that stated that this sounds like homework.
Maybe it does, I've never taken a Linux class, been a Windows admin
for many years, just starting to scratch the surface of Linux. I
changed the filenames in my description, but the problem is actually a
real-world one. I migrated a proprietary email system (Gordano GMS)
from Windows to Linux a couple of weeks ago. Most accounts work fine,
but a few hundred don't and I found that they don't because the
INBOX.MBX file case doesn't match the INBOX.IDX file case, so the

So, why not change them all to the same case for all users, and have
everything be stadard.

for i in `find . -iname inbox.mbx`
do
j=`dirname $i`
mv $i ${j}/inbox.mbx
done

and then the same for inbox.idx

system can't find the index for the mailbox file and hence shows the
mailbox as empty. I need to find all directories where these two
files have a different case so that I can fix that problem. In
Windows, this didn't matter because there is no case sensitivity, but
obviously in Linux this broke the mailbox. Gordano support is trying
to figure out how to fix this programmatically also, but they're slow
as hell so I was trying a different avenue...

Pete.

On Wed, 6 Aug 2008 16:16:17 +0000 (UTC), "Auric__"
not.my.real at (no spam) email.address> wrote:

On Tue, 05 Aug 2008 23:30:23 GMT, P1 wrote:

I'm in need of script that would allow me to find the following but
I've never scripted anything. Hoping to get some help as I just don't
have time to learn scripting just for this particular task, although
it's definitely something I want to put on my todo list...

Find all subfolders with a file.ext1 and file.ext2 but only where the
letter case of "file" is different. There are three possible ways the
name can be spelled: file, File and FILE.

So a subfolder containing both file.ext1 and File.ext2 would be found
since the case is different, but a subfolder containing FILE.ext1 and
FILE.ext2 would not, since the case matches.

That sounds very much like some sort of homework.
Holger Petersen...
Posted: Thu Aug 07, 2008 12:24 am
Guest
Unruh <unruh-spam at (no spam) physics.ubc.ca> writes:

Quote:
P1 <p1 at (no spam) eagency.com> writes:

Thought about that too, but unfortunately, there's a config file or
something somewhere that tells the system how the file name is
spelled, and it's not the same for all users, so I can't standardize
it, unless Gordano rewrites their code to ignore case or we can find
the config file and modify the names there. I don't even know if it
is a config file or if it's hard-coded.

If it is hard coded then it should be the same for all. You say they are
not the same for all.

It might be that *new* Files have another 'case' then old ones?

Quote:
You are left with the problem that if the two names disagree, then which is
the one that determines what the common name should be?

What about a (symbolic) link from all spellings to the existing file ?


Quote:
Pete

On Wed, 06 Aug 2008 22:03:08 GMT, Unruh <unruh-spam at (no spam) physics.ubc.ca
wrote:

[please don't top-post...]

Yours, Holger
birre...
Posted: Thu Aug 07, 2008 5:26 am
Guest
On 2008-08-06 22:24, P1 wrote:

Quote:
.... I migrated a proprietary email system (Gordano GMS)
from Windows to Linux a couple of weeks ago. Most accounts work fine,
but a few hundred don't and I found that they don't because the
INBOX.MBX file case doesn't match the INBOX.IDX file case, so the
system can't find the index for the mailbox file and hence shows the
mailbox as empty.
....

Yes, you did not expected that problem due to lack of experience
of mixing windows files and linux files.

I have had this types of problems in decades and think about it before I start
migrations :-)

So, what I do is just install a mail system in linux, in my care it's
a postfix/cyrus imap combo , then the users just open the
old and new mailboxes in thunderbird or any other imap client, and
move their mail folders to the new server.

That is avoiding the problem completely :-)

Another common problem you may get is wrong permission on files,
so everyone can read/write others mail, or they can even be set as exec
files, making it possible for users to exec them and get a random
bad result.

/bb
noi ance...
Posted: Thu Aug 07, 2008 2:46 pm
Guest
On Wed, 06 Aug 2008 13:24:24 -0700, P1 typed this message:

Quote:
You're the second person that stated that this sounds like homework.
Maybe it does, I've never taken a Linux class, been a Windows admin for
many years, just starting to scratch the surface of Linux. I changed
the filenames in my description, but the problem is actually a
real-world one. I migrated a proprietary email system (Gordano GMS)
from Windows to Linux a couple of weeks ago. Most accounts work fine,
but a few hundred don't and I found that they don't because the
INBOX.MBX file case doesn't match the INBOX.IDX file case, so the system
can't find the index for the mailbox file and hence shows the mailbox as
empty. I need to find all directories where these two files have a
different case so that I can fix that problem. In Windows, this didn't
matter because there is no case sensitivity, but obviously in Linux this
broke the mailbox. Gordano support is trying to figure out how to fix
this programmatically also, but they're slow as hell so I was trying a
different avenue...

Pete.

On Wed, 6 Aug 2008 16:16:17 +0000 (UTC), "Auric__"
not.my.real at (no spam) email.address> wrote:

On Tue, 05 Aug 2008 23:30:23 GMT, P1 wrote:

I'm in need of script that would allow me to find the following but
I've never scripted anything. Hoping to get some help as I just don't
have time to learn scripting just for this particular task, although
it's definitely something I want to put on my todo list...

Find all subfolders with a file.ext1 and file.ext2 but only where the
letter case of "file" is different. There are three possible ways the
name can be spelled: file, File and FILE.

So a subfolder containing both file.ext1 and File.ext2 would be found
since the case is different, but a subfolder containing FILE.ext1 and
FILE.ext2 would not, since the case matches.

That sounds very much like some sort of homework.

I replied to this in other groups and I overthought the solution.

$ find $HOME -iname file\* -printf "%h \n" | sort -u > list.txt

Produces a unique list of all sub-folders that contain the case
insensitive files beginning with the name "file", that is file*, File*
and FILE*

file\* is the same as "file*" or -iname "file*"
more to the point file.\* is the same as "file.*"

-printf "%h \n" simply prints only the leading folder names

| sort -u > list.txt uniquely sorts the output from the find command.


Originally, I thought you wanted just the folders containing File* and
FILE* files without the file*.
P1...
Posted: Fri Aug 08, 2008 1:16 pm
Guest
P1 wrote:
Quote:
I'm in need of script that would allow me to find the following but
I've never scripted anything. Hoping to get some help as I just don't
have time to learn scripting just for this particular task, although
it's definitely something I want to put on my todo list...

Find all subfolders with a file.ext1 and file.ext2 but only where the
letter case of "file" is different. There are three possible ways the
name can be spelled: file, File and FILE.

So a subfolder containing both file.ext1 and File.ext2 would be found
since the case is different, but a subfolder containing FILE.ext1 and
FILE.ext2 would not, since the case matches.

Hope that makes sense...

Thanks,
Pete.

Thanks for all the helpful responses guys, I learned a few things here :)

-Pete
P1...
Posted: Fri Aug 08, 2008 6:08 pm
Guest
Unruh wrote:

Quote:
for i in `find . -iname inbox.MBX`
do
j=`dirname $i`
k=`basename $i .MBX`
l=`find $j -iname inbox.IDX`
if [ "`basename $l .IDX`" != "$k" ]; then
echo $k
fi
done


Being a noob to this, it took me a while to figure out what was wrong
with this script, because it made sense on paper but yet it was
resulting in listing ALL user directories. So I started breaking it
down and put echo $variable statements before the end and found that
basename wasn't stripping the suffix, it's apparently case-sensitive Smile
Here's my modified version of it:

for i in `find . -iname inbox.mbx`
do
dir=`dirname $i`
mbxname=`basename $i .mbx`
idxpath=`find $dir -iname inbox.idx`
idxname=`basename $idxpath .idx`
if [ "$idxname" != "$mbxname" ]; then
echo Case Mismatch in $dir; else
echo Match OK in $dir
fi
done

Thanks for the help and the lesson Smile
Pete.
PS. Btw, how can I pipe that output to "sort" or "count"?
bb...
Posted: Mon Aug 11, 2008 4:14 am
Guest
On 2008-08-09 01:08, P1 wrote:
Quote:
Unruh wrote:

for i in `find . -iname inbox.MBX`
do
j=`dirname $i`
k=`basename $i .MBX`
l=`find $j -iname inbox.IDX`
if [ "`basename $l .IDX`" != "$k" ]; then
echo $k
fi
done


Being a noob to this, it took me a while to figure out what was wrong
with this script, because it made sense on paper but yet it was
resulting in listing ALL user directories. So I started breaking it
down and put echo $variable statements before the end and found that
basename wasn't stripping the suffix, it's apparently case-sensitive Smile
Here's my modified version of it:

for i in `find . -iname inbox.mbx`
do
dir=`dirname $i`
mbxname=`basename $i .mbx`
idxpath=`find $dir -iname inbox.idx`
idxname=`basename $idxpath .idx`
if [ "$idxname" != "$mbxname" ]; then
echo Case Mismatch in $dir; else
echo Match OK in $dir
fi
done

Thanks for the help and the lesson Smile
Pete.
PS. Btw, how can I pipe that output to "sort" or "count"?

BTW, when using find recursive together with renaming, it can be a good idea
to search from the depth and up, -depth option.

/bb
 
Page 1 of 1       All times are GMT - 5 Hours
The time now is Sat Nov 22, 2008 11:22 am