nik
nik

Reputation: 2584

how can I print the name of all files from a folder

I have like 10000 files in a folder and I want to know which one is doublicated. I like to save only the names of them in a txt file

Is there any way to do it?

My files look like this. as an example

..._P2_A1-(01)_....tx

For me it is doublicated when I have the first part twice QEX2_P2_A1

I did try to print it but with no success for example, here is one solution Bash: How to print the filename of the nth file in a folder or Extract filename and extension in Bash which did not work for me. I have tried to search it but I could not find any solution

Upvotes: 1

Views: 84

Answers (1)

anubhava
anubhava

Reputation: 785128

You can use printf + awk to print all partially duplicated filenames:

printf "%s\n" *.txt | awk -F '_' '{k=$1 FS $2 FS $3} k in seen{dups[seen[k]]=k; dups[$0]=k}
  {seen[k]=$0} END{for (f in dups) print dups[f] " => " f}'

Upvotes: 2

Related Questions