Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
07-22-2003, 03:34 PM
|
#1
|
Member
Registered: Mar 2002
Location: San Francisco, CA
Distribution: Open/FreeBSD, Gentoo, SuSE
Posts: 511
Rep:
|
grep a line in a file from dir
I have a bunch of files in a directory and I want to find any lines in any of the files that match "addresses"
What tools would i need to use to acheive this?
I can grep words in a single file, but never did it for a directory of files.
|
|
|
07-22-2003, 04:10 PM
|
#2
|
Senior Member
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552
Rep:
|
You can use something similar to:
grep addresses *
grep addresses *.txt
...
|
|
|
07-22-2003, 05:11 PM
|
#3
|
Member
Registered: Feb 2003
Location: San Antonio
Distribution: Suse 9.0 Professional
Posts: 843
Rep:
|
If you aren't sure it is is Addresses or addresses, then
grep -i addresses *
will find all instances case insensitive.
Bonus hint: you can perform multiple instances of grep.
For example, the files find 14,000 matches, but you want the ones with John Smith on the same line...
grep -i addresses * |grep -i 'john smith'
RO
|
|
|
07-24-2003, 12:54 AM
|
#4
|
Member
Registered: Mar 2002
Location: San Francisco, CA
Distribution: Open/FreeBSD, Gentoo, SuSE
Posts: 511
Original Poster
Rep:
|
Excellent! Thank you.
Now, second part;
I have directories and Directories of files and some of these top level directories have a directory call '.xvpics' i'd like to remove.
How do I grep for this folder within 300 some top level dirs?
|
|
|
07-24-2003, 02:04 AM
|
#5
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
rm -rf `find . -name .xvpics`
|
|
|
All times are GMT -5. The time now is 11:56 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|