LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 07-22-2003, 04:34 PM   #1
bkeating
Member
 
Registered: Mar 2002
Location: San Francisco, CA
Distribution: Open/FreeBSD, Gentoo, SuSE
Posts: 511

Rep: Reputation: 38
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.
 
Old 07-22-2003, 05:10 PM   #2
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
You can use something similar to:
grep addresses *
grep addresses *.txt
...
 
Old 07-22-2003, 06:11 PM   #3
RolledOat
Member
 
Registered: Feb 2003
Location: San Antonio
Distribution: Suse 9.0 Professional
Posts: 843

Rep: Reputation: 30
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
 
Old 07-24-2003, 01:54 AM   #4
bkeating
Member
 
Registered: Mar 2002
Location: San Francisco, CA
Distribution: Open/FreeBSD, Gentoo, SuSE
Posts: 511

Original Poster
Rep: Reputation: 38
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?
 
Old 07-24-2003, 03:04 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
rm -rf `find . -name .xvpics`
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 09:22 AM
Multi-line return from grep into an array? rose_bud4201 Programming 2 06-14-2005 05:11 PM
Grep pattern first line of a file ericcarlson Linux - Newbie 11 07-20-2004 11:51 AM
Blank line - grep. liguorir Linux - Software 1 04-24-2004 10:03 AM
line addressing with grep (shell scripting) j2dizzo Linux - General 13 03-03-2004 10:36 AM


All times are GMT -5. The time now is 06:43 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration