The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Combination of find -xargs & wc -l mr_bold UNIX for Dummies Questions & Answers 4 07-08-2008 06:07 AM
Problem using find and xargs quixote Shell Programming and Scripting 5 05-02-2008 11:24 PM
command usage on find with xargs and tar darkrainbow AIX 3 12-25-2007 06:25 PM
strange behavior of find with xargs jerardfjay Shell Programming and Scripting 9 08-09-2007 09:06 AM
find | xargs cat asal_email Shell Programming and Scripting 4 03-17-2005 12:16 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-17-2009
DownunderDave DownunderDave is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 2
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.
  #2 (permalink)  
Old 03-17-2009
wabard wabard is offline
Registered User
  
 

Join Date: Mar 2009
Location: Adelaide, SA & Perth, WA - Australia
Posts: 25
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 ...

Code:
find . -type f -name "developer.txt" -exec cat {} \;
  #3 (permalink)  
Old 03-17-2009
DownunderDave DownunderDave is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 2
That worked, but need filename output

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.
  #4 (permalink)  
Old 03-17-2009
wabard wabard is offline
Registered User
  
 

Join Date: Mar 2009
Location: Adelaide, SA & Perth, WA - Australia
Posts: 25
Lightbulb An alternate method to include formatting the filename...

Quote:
Originally Posted by DownunderDave View Post
Thanks for that Wabard.

I have just added another option to the find command so I know which file is being 'cat'ed.
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).

Code:
find . -type f -name "*.c" -exec awk 'BEGIN{s="====================="} {if(n++<1){printf("%s %s %s\n",s,FILENAME,s)}else{print}}' {} \;
  #5 (permalink)  
Old 03-17-2009
curleb curleb is offline
Registered User
  
 

Join Date: Mar 2008
Location: Here, in my Ivory Tower...
Posts: 68
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...

Quote:
find command works correctly and when I copy and paste the output of that with a preceeding 'cat'
Have you tried to wrap the whole mess into a simple script like the following:

Code:
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.
Closed Thread

Bookmarks

Tags
linux unix xargs cat find

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:16 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0