find | xargs cat

Hi,

I am having trouble getting a combination of commands to work.

I need to traverse through all sub-directories of a certain directory and 'cat' the contents of a particular file in the sub-directories.

The commands on their own work but when I combine them I get no output.

The command I am trying to get working is:
find . -type f -name "developer.txt" | xargs cat

The find command works correctly and when I copy and paste the output of that with a preceeding 'cat', the contents are printed out. However together with the pipe the commands are not working.

1) Your command seems for work for me under Linux and Solaris

2) The find command has its own execution capability (-exec).

Thus you may want to try ...

find . -type f -name "developer.txt" -exec cat {} \;

Thanks for that Wabard.

That worked a treat for command. I'm trying to run this on SuSe Linux.
I have just added another option to the find command so I know which file is being 'cat'ed.

find . -type f -name "developer.txt" -ls -exec cat {} \;

Cheers,
Dave.

for one, wouldn't either less or more (or even view) serve better than cat? I'm assuming it's more of an interactive session you're looking for...? While find does allow for its own -exec parameter, xargs is faster by a long-shot.

However, it reads as though your problem is more so with the terminal than the shell commands...

Have you tried to wrap the whole mess into a simple script like the following:

for item in $(find . -type f -name "developer.txt" ) ;do cat $item ;done 

This will just do a massive screen dump, which I doubt is what you'd want... Swapping in other utils, like less, more or view will retain some composure and allow you to view and/or exit the file(s) individually.

Regarding your requirement for the filename to be output, please note the following should handle your full requirements and should be compatible with all U**X flavors... (I've searched for *.c in my example).

find . -type f -name "*.c" -exec awk 'BEGIN{s="====================="} {if(n++<1){printf("%s %s %s\n",s,FILENAME,s)}else{print}}' {} \;