Union, intersection, and exclusion with FIND command?

I need to manage lists using find command. Suppose the lists have random names in fuzzy lists (ie, their intersection is not an empty set). How to do it:

A \ B

find files in list A except files in list B

Intersection B

find files common to lists A and B

Please refer to here.

Compound B

find all files in two lists

<strong> Examples

$ find . | awk -F"/" '{ print $2 }'

.zcompdump
.zshrc
.bashrc
.emacs

$ find ~/bin/FilesDvorak/.* -maxdepth 0 | awk -F"/" '{ print $6 }'

.bashrc
.emacs
.gdbinit
.git

      

I want to:

A \ B :

.zcompdump
.zshrc

      

Intersection B :

.bashrc
.emacs

      

Union B :

.zcompdump
.zshrc
.bashrc
.emacs
.bashrc
.emacs
.gdbinit
.git

      

Try a crossroads

When I keep the outputs in separate lists, I can't figure out why the command doesn't accept general things, i.e. the above intersection:

find -f all_files -and -f right_files .

      

The questions arose from the question:

  • find ~ / bin / FilesDvorak /.* -maxdepth 0- and ~ / .PAST_RC_files /.*

  • Please consult for a recursive search <and href = "/ questions / 2589087 / how-can-i-combine-the-find-commands"> Click here!

  • find ~ / bin / FilesDvorak /.* -maxdepth 0 and list

-1


a source to share


2 answers


Seriously, that's what comm (1) is for. I don't think the man page could be much clearer: http://linux.die.net/man/1/comm



+3


a source


There are several tools that can help you find intersections in file lists. "find" is not one of them. Find - Search for files that match certain criteria in the file system.

Here are some ways to find the answer.

To create two lists of files

find . -maxdepth 1 | sort > a
(cd ~/bin/FilesDvorak/; find . -maxdepth 1 | sort > b)

      

You now have two files a and b that contain directory entries without recursion into subdirectories. (To remove the leading. /, You can add sed -e /^./// or your first awk command in between looking for sort)

To find the Union



cat a b | sort -u 

      

To find A \ B

comm -23 a b 

      

To find the intersection

comm -12 a b

      

See 'man comm' and 'man find' for more information.

+1


a source







All Articles