sattu sattu - 1 month ago 5x
Bash Question

Get filepaths for uniqe files in bash

I have following folder structure:


I want the output to be


Any of the path to e.txt would work. So far, I am able to filter out the unique files, but I am loosing value of full path.

find . -name '*.txt' | awk -F "/" '{print $NF}' | uniq

Output is


Is there any way using awk, sed or any other command to print the full path in above scenario?


You can use awk:

awk -F/ '!seen[$NF]++' file


seen is an associative array with key as $NF (last field).