Find the number of non-duplicate names recursively.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find the number of non-duplicate names recursively.
# 1  
Old 05-10-2010
Find the number of non-duplicate names recursively.

Hi, here comes another newbie question:

How to find the number of non-duplicate names recursively?

For example, my files are stored in the folders like:

Quote:
1
1.txt

2
1.txt
2.txt
3.txt

If I do

Code:
find . -depth -name "*.txt" | wc -l

This will gives out a result "4". One .txt file named "1.txt" in folder "1",
and three other .txt files named "1.txt", "2.txt" and "3.txt" in folder "2".

However, some times, I would like to show the number of non-duplicate file names:
say:
1.txt
2.txt
3.txt

in total, there are "3", I would like a command to give out a result "3", rather than "4".

Can anybody give me a hand?

Best Regards
JIA
# 2  
Old 05-10-2010
Code:
find . -depth -name "*.txt" |sort -u | wc -l

# 3  
Old 05-10-2010
Code:
find . -depth -name "*.txt" | awk -F"/" ' !a[$NF]++ ' | wc -l

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find command not searching recursively

I'm searching for particular scripts that contain pattern "BASIS" so I used the following command: find . -type f -print | xargs grep "BASIS" or find . -type f -exec grep "BASIS" {} \; However, I found out that the find command in the UNIX box that I'm working on doesn't find files... (6 Replies)
Discussion started by: The Gamemaster
6 Replies

2. Shell Programming and Scripting

Using awk to append incremental numbers to the end of duplicate file names.

I'm currently working on a script that extracts files from a .zip, runs an sha1sum against them and then uses awk to pre-format them into zomething more readable thusly: Z 69 89e013b0d8aa2f9a79fcec4f2d71c6a469222c07 File1 Z 69 6c3aea28ce22b495e68e022a1578204a9de908ed File2 Z 69... (5 Replies)
Discussion started by: Ethereal
5 Replies

3. Solaris

Display the number of files in a directory and recursively in each subdirectory

Display the number of files in a directory and recursively in each subdirectory To look something like below, for example /var 35 /var/tmp 56 /var/adm 46Any ideas how can we do this? Got a sun cluser global mount point which takes ages to mount everytime, need to understand... (5 Replies)
Discussion started by: jakerock
5 Replies

4. Solaris

Display the number of files in a directory and recursively in each subdirectory

Display the number of files in a directory and recursively in each subdirectory To look something like below, for example /var 35 /var/tmp 56 /var/adm 46 Any ideas how can we do this? :wall: (1 Reply)
Discussion started by: jakerock
1 Replies

5. Shell Programming and Scripting

Find duplicate based on 'n' fields and mark the duplicate as 'D'

Hi, In a file, I have to mark duplicate records as 'D' and the latest record alone as 'C'. In the below file, I have to identify if duplicate records are there or not based on Man_ID, Man_DT, Ship_ID and I have to mark the record with latest Ship_DT as "C" and other as "D" (I have to create... (7 Replies)
Discussion started by: machomaddy
7 Replies

6. Shell Programming and Scripting

duplicate index names renamed

Hello everyone ! Please have a minute and see if you know how to script this I have a file like this: "create table .... ... create index n112 on ... ... create table ... .... create index n113 on... ... create table ... create index n112 on ...! duplicate ... (1 Reply)
Discussion started by: sotoc79
1 Replies

7. UNIX for Dummies Questions & Answers

Some questions - renaming duplicate names

I have a file that looks like this 2 4 10 500 tim9 5 8 14 700 tim9 3 5 15 432 john1 1 4 12 999 ellen2 So basically what i want to do is fine duplicate names on column 5 and rename it with an extention (i.e. tim9_1 and tim9_2). so the output file will look like this 2 4 10 500 tim9_1... (1 Reply)
Discussion started by: kylle345
1 Replies

8. Shell Programming and Scripting

How to : Find duplicate number from file? with bash

Thanks AVKlinux (6 Replies)
Discussion started by: avklinux
6 Replies

9. UNIX for Advanced & Expert Users

Recursively check the file/dir names

Hi, ' recgrep find . | xargs grep ' is used to scan the contents recursively. I have a different requirement. I need to scan just the names and check for a pattern and display with fullpath. Is that already available? Closest that I am trying is 'ls -R | grep pattern' Here I would get multiple... (1 Reply)
Discussion started by: eagercyber
1 Replies

10. Shell Programming and Scripting

Bash Script duplicate file names

I am trying to write a housekeeping bash script. Part of it involves searching all of my attached storage media for photographs and moving them into a single directory. The problem occurs when files have duplicate names, obviously a file called 001.jpg will get overwritten with another file... (6 Replies)
Discussion started by: stumpyuk
6 Replies
Login or Register to Ask a Question