sattu sattu - 1 year ago 111
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?

Answer Source

You can use awk:

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


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download