LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-14-2006, 08:48 PM   #1
MiniMe001
Member
 
Registered: Nov 2004
Location: US
Distribution: Gentoo
Posts: 59

Rep: Reputation: 15
cat recursively


Is this possible? If not, anyone want to tell me how to write a shell script that will /make/ it possible?

I really want this for
cat --recursively | grep 'find this'
so if there's another way to do that, that'd be great. I just want to find a line of code without searching forever... >_>
 
Old 07-14-2006, 08:59 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I don't see what recursive behavior in cat would mean--or what it would do. Recursion means that a program can call itself. Perhaps you can show us what the ultimate problem is.
 
Old 07-14-2006, 09:20 PM   #3
svaucher
LQ Newbie
 
Registered: Aug 2004
Distribution: RH 9.0
Posts: 4

Rep: Reputation: 0
I guess you mean that you want to cat everything recursively in a directory.

1/ use find
% find <dir> -type f -exec cat \{} \;

2/ use tar (a bit perverted), you can use this technique to do quick network copies...
% tar cf - <dir>

If you want to find the **name** of the file that contains the pattern:

% grep -lR <pattern> <dir>

or find

% find <dir> -type f -exec grep -l <pattern> \{} \;

Hope that helps,
Stephane Vaucher
 
Old 07-14-2006, 10:42 PM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
I personally like 'grep -Hr PATTERN PATH'. This will perform a recursive grep on all the files in path and subdirectories for the pattern PATTERN, then print out data of the form:
Code:
log.txt: This is a log entry containing PATTERN.
 
Old 07-15-2006, 11:40 AM   #5
MiniMe001
Member
 
Registered: Nov 2004
Location: US
Distribution: Gentoo
Posts: 59

Original Poster
Rep: Reputation: 15
Thanks, all. This helps a good bit.
 
Old 07-16-2006, 04:59 PM   #6
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
I prefer the following:

$ find . | xargs grep 'TEXT'
or
$ grep 'TEXT' `find .`

Note: in the second command back ticks: `` used, not apostrophes: ''. Dot (.) means a current directory.
 
Old 07-16-2006, 05:47 PM   #7
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by firstfire
I prefer the following:

$ find . | xargs grep 'TEXT'
or
$ grep 'TEXT' `find .`

Note: in the second command back ticks: `` used, not apostrophes: ''. Dot (.) means a current directory.
The disadvantage of these is that they do not print the name of the file containing the line in question.
 
Old 07-17-2006, 12:12 AM   #8
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Quote:
Originally Posted by Matir
The disadvantage of these is that they do not print the name of the file containing the line in question.
If you want filenames, just add '-H' option to `grep':
Code:
 grep -H 'text' `find .`
 
Old 07-17-2006, 12:17 AM   #9
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
True. In hindsight, that would work with the xargs version as well. Ignore my previous remarks, lol.
 
  


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
stripping ^m recursively. SaxiDawg Linux - General 1 06-07-2006 04:27 AM
rm dir recursively allelopath Linux - General 6 01-06-2006 11:37 AM
lowercase recursively cubax Linux - General 6 05-29-2005 04:20 PM
RemovePkg Recursively? Kenji Miyamoto Slackware 3 05-23-2005 08:33 AM
how to rm backup files recursively wazoo Linux - Newbie 6 12-31-2004 10:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:44 PM.

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