I have used find and saved the result to file.txt file. Now I want to check files with same name sorted highest count first. e.g.:
/Volumes/1 drive/foo
/Volumes/1 drive/bar
/Volumes/1 drive/foo2
/Volumes/2 drive/foo
/Volumes/2 drive/bar2
/Volumes/3 drive/1/foo
/Volumes/3 drive/2/bar
I am running this command:
cat file.txt | awk -F '/' '{print $NR}' | uniq -c | sort
But awk output doesn't work correctly, it prints only first line:
Volumes
1 drive
foo
EDIT: The output should be:
3 foo
2 bar
1 foo2
1 bar2
If you are trying to delete the paths and only keep the part after the last slash, you can do it with
sedlike this:sed 's|.*/||'.Note that you need a sorted column for
uniq -cto work. So then if you want its output sorted as well, you need twosortcalls:If you want to use
awk, then you probably need$NFand not$NR:This use of
awkis shown in this answer.