From: laredotornado on 7 Feb 2010 18:17 Hi, How would I search for files that have the same name, but potentially different case, living in the same directory? For example, I would want to find files like /dir1/image1.gif /dir1/IMAGE1.gif but I don't care about /dir1/image1.gif /dir1/dir2/image1.gif ? Hope this question makes sense, - Dave
From: Seebs on 7 Feb 2010 18:21 On 2010-02-07, laredotornado <laredotornado(a)zipmail.com> wrote: > How would I search for files that have the same name, but potentially > different case, living in the same directory? For example, I would > want to find files like Within a directory: for file in * do if ls | grep -v "^$file\$" | grep -qi "^$file\$" then echo "found similar matches for '$file'." fi done There's probably other ways, whether that'll suit or not depends a lot on your use case. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Janis Papanagnou on 7 Feb 2010 18:31 laredotornado wrote: > Hi, > > How would I search for files that have the same name, but potentially > different case, living in the same directory? For example, I would > want to find files like > > /dir1/image1.gif > /dir1/IMAGE1.gif > > but I don't care about > > /dir1/image1.gif > /dir1/dir2/image1.gif > > ? Hope this question makes sense, - Dave This awk program stores the converted filenames that it reads from stdin in lowercase and prints any new filename that matches case-insensitive... awk 'tolower($0) in f ; { f[tolower($0)] }' You can feed files from a current directory awk 'tolower($0) in f ; { f[tolower($0)] }' * or (if case insensitive directories are not a problem) from a directory tree find . | awk 'tolower($0) in f ; { f[tolower($0)] }' Just one way to approach the task. Janis
From: Janis Papanagnou on 7 Feb 2010 20:14 Janis Papanagnou wrote: > laredotornado wrote: >> Hi, >> >> How would I search for files that have the same name, but potentially >> different case, living in the same directory? For example, I would >> want to find files like >> >> /dir1/image1.gif >> /dir1/IMAGE1.gif >> >> but I don't care about >> >> /dir1/image1.gif >> /dir1/dir2/image1.gif >> >> ? Hope this question makes sense, - Dave > > This awk program stores the converted filenames that it reads from stdin > in lowercase and prints any new filename that matches case-insensitive... > > awk 'tolower($0) in f ; { f[tolower($0)] }' > > You can feed files from a current directory > > awk 'tolower($0) in f ; { f[tolower($0)] }' * Didn't know what I was thinking with the previous line; should have been ls | awk '...' or ls */* | awk '...' or somesuch. > > or (if case insensitive directories are not a problem) from a directory > tree > > find . | awk 'tolower($0) in f ; { f[tolower($0)] }' > > Just one way to approach the task. And since I am posting anyway I can point to the terse "golf version" as well... find . | awk 'f[tolower($1)]++' > > Janis
From: Ed Morton on 8 Feb 2010 08:25 On 2/7/2010 7:14 PM, Janis Papanagnou wrote: > Janis Papanagnou wrote: >> laredotornado wrote: >>> Hi, >>> >>> How would I search for files that have the same name, but potentially >>> different case, living in the same directory? For example, I would >>> want to find files like >>> >>> /dir1/image1.gif >>> /dir1/IMAGE1.gif >>> >>> but I don't care about >>> >>> /dir1/image1.gif >>> /dir1/dir2/image1.gif How do you feel about: /dir1/image1.gif /DIR1/image1.gif or: /dir1/dir2 /dir1/DIR2 where dir2 and DIR2 are directories? >>> ? Hope this question makes sense, - Dave >> >> This awk program stores the converted filenames that it reads from stdin >> in lowercase and prints any new filename that matches case-insensitive... >> >> awk 'tolower($0) in f ; { f[tolower($0)] }' >> >> You can feed files from a current directory >> >> awk 'tolower($0) in f ; { f[tolower($0)] }' * > > Didn't know what I was thinking with the previous line; should have been > > ls | awk '...' or ls */* | awk '...' or somesuch. > >> >> or (if case insensitive directories are not a problem) from a directory >> tree >> >> find . | awk 'tolower($0) in f ; { f[tolower($0)] }' >> >> Just one way to approach the task. > > And since I am posting anyway I can point to the terse "golf version" as > well... > > find . | awk 'f[tolower($1)]++' ITYM: find . | awk 'f[tolower($0)]++' or if the OP really only cares about files with matching names but does care about differentiating directories with different case: find . -type f | awk -F'/' '{file=tolower($NF); sub(/[/][^/]+$/,"",$0)} f[$0 "/" file]++' Usual caveat about file names that contain newlines. Regards, Ed.
|
Next
|
Last
Pages: 1 2 3 4 Prev: is there a bash equivalent of "this" ... Next: Unix Script to process records in group |