Bash: Sort files from 'find' by contents
bash, find, piping, shell, sorting
Solution
For completeness sake here are a few more ways of doing that:
- `find -maxdepth 1 -type f -iname '*key*' -not -name '*~' -exec cat {} \; | sort`
- `find -maxdepth 1 -type f -iname '*key*' -not -name '*~' | xargs cat | sort`
- `cat $(find -maxdepth 1 -type f -iname '*key*' -not -name '*~') | sort`
Problem
I have the line: ``` find -maxdepth 1 -type f -iname '*key*' -not -name '*~' ``` I want to extract the contents (which should be text) of all the files returned and pipe that into `sort` to be sorted alphabetically. I've tried piping the output of the above line directly into `sort` but this results in the file names being sorted rather than their contents. Do I need to turn the output of `find` into an array and then have it processed by `sort`? [edit] The output I want is the sorted contents.