LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS
User Name
Password
CentOS This forum is for the discussion of CentOS Linux. Note: This forum does not have any official participation.

Notices


Reply
  Search this Thread
Old 01-31-2017, 07:04 AM   #1
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Rep: Reputation: Disabled
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.
 
Old 01-31-2017, 07:58 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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.

-u = unique
-n = numeric sort
-k = field specification

Default field separator is white space.

If you're doing pure tape numbers counting which field has the tape number and doing the -unk<field> should work.

Last edited by MensaWater; 01-31-2017 at 08:19 AM.
 
1 members found this post helpful.
Old 01-31-2017, 08:11 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,333
Blog Entries: 3

Rep: Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730
Quote:
Originally Posted by MensaWater View Post
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.
 
Old 02-02-2017, 06:35 AM   #4
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Original Poster
Rep: Reputation: Disabled
sorry guys been very busy at work,

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

https://s29.postimg.org/3uwg6w0lz/media.png
 
Old 02-02-2017, 06:44 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,333
Blog Entries: 3

Rep: Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730
Check out awk.

Code:
find . -type f -exec fsfileinfo "{}" \; | awk '$1 == "Media:" { print $2; }';
find . -type f -exec fsfileinfo "{}" \; | awk '$1 == "Media:" { print $2; }' | sort -u;
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

Code:
man find
 
Old 02-02-2017, 08:21 AM   #6
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Original Poster
Rep: Reputation: Disabled
thanks Turbo
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
help with find command (specifically the -o and -exec options) Bez Vozvrata Linux - General 3 06-06-2010 03:46 PM
find command with exec cola Linux - Newbie 5 06-01-2010 01:25 PM
'find' gives different results when using -mtime with -print vs -exec BrianK Linux - General 1 12-08-2008 10:32 AM
find with -exec: no command output David the H. Linux - Software 5 01-03-2008 01:53 AM
redhat 9.0 how to use the command 'find' with the action -exec arvin_shu Linux - Newbie 3 11-30-2005 07:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS

All times are GMT -5. The time now is 07:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration