Unix/Linux Go Back    


UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

How do I grep in specific file types?

UNIX for Dummies Questions & Answers


 
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-12-2008
bbbngowc bbbngowc is offline
Registered User
 
Join Date: Jul 2007
Last Activity: 11 June 2017, 12:18 PM EDT
Posts: 346
Thanks: 2
Thanked 4 Times in 4 Posts
How do I grep in specific file types?

I have a directory with file types ending .log, .mml, .gll, .dll . How can I grep expressions only in say the .log files?
Sponsored Links
    #2  
Old Unix and Linux 02-12-2008
MaestroRage MaestroRage is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 4 April 2009, 2:28 AM EDT
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
now i'm not 100% on this, but i'm fairly sure you can solve this issue by using pipe commands.

ls *.log | grep whatever whatever

the ls *.log will find only the files ending with .log, and whatever output you get from this, is carried over by the "|" and lets you manipulate it further.

Hope that helped.
Sponsored Links
    #3  
Old Unix and Linux 02-13-2008
agn agn is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 6 August 2013, 7:49 AM EDT
Posts: 345
Thanks: 0
Thanked 21 Times in 21 Posts

Code:
grep $pattern *.log

But if you have thousands of files, it may break. In that case, you can use


Code:
find $dir -type f -name '*.log' -exec grep -o $pattern {} \;

OR


Code:
find $dir -type f -name '*.log' -print0 | xargs -0 grep -o $pattern

    #4  
Old Unix and Linux 02-18-2008
bbbngowc bbbngowc is offline
Registered User
 
Join Date: Jul 2007
Last Activity: 11 June 2017, 12:18 PM EDT
Posts: 346
Thanks: 2
Thanked 4 Times in 4 Posts
Thanks agn, that worked.
Sponsored Links
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with using different types of GREP SilvarHawke Homework & Coursework Questions 11 11-29-2011 07:08 AM
grep specific ipaddress from a file tbd UNIX for Dummies Questions & Answers 1 11-20-2011 06:02 PM
Help with grep at specific field of a file techmoris Shell Programming and Scripting 7 10-21-2010 11:21 AM
grep a specific line from a file Max89 Shell Programming and Scripting 4 11-24-2009 12:31 PM
grep on specific line of the file rider29 Shell Programming and Scripting 4 05-29-2008 09:57 AM



All times are GMT -4. The time now is 11:55 PM.