find exec command that will only show unique results
CentOSThis forum is for the discussion of CentOS Linux. Note: This forum does not have any official participation.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
find exec command that will only show unique results
hi all,
im trying to run a command like this -
find -type f -exec fsfileinfo {} \; | grep Media
so what this will do is print out on the screen all the Media/tape numbers that contain a file but i get a long list as it prints the same numbers aswell not just unique numbers only
is there a way to just print tape numbers just once if there unique?
many thanks,
rob
Last edited by robertkwild; 01-31-2017 at 07:07 AM.
You could pipe the line into sort specifying a unique sort on the specific field. You didn't show what your output looks like so I don't know which field would be the tape number (or if your tape number is actually just a number rather than alphanumeric).
Testing with "ls -l" output on my CentOS system:
Sort by permissions (first column) which is NOT numeric:
ls -l |sort -uk1.1,1.12
Sort by links (second column):
ls -l |sort -unk2
Usually sort by an entire field just requires the field number as in the second example above but it appears that sorts on alpha are requiring the full field specification including the trailing space.
You didn't show what your output looks like so I don't know which field would be the tape number (or if your tape number is actually just a number rather than alphanumeric).
Indeed. Please show some lines of output that you wish filtered.
i attach the screenshot of what the results are meant to look like using this command -
fsfileinfo file_name
but because im doing a fsfileinfo on the whole folder instead of just one file what you do is you cd out of the directory and do this command -
find -type f -exec fsfileinfo {} \; | grep Media
this finds all the media ie tape numbers for all the files in the folder but i get masses of screenshots, so i was just wondering can i just make a nice list of unique tapes i need instead of it listing all of them
awk is a simple scripting language to scan and modify text. Its syntax is basically a lot of implied if-then statements.
If you are not in the directory hierarchy containing your target files, then change the path for find. If you need to restrict to certain file names, then add -name
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.