How do I grep in specific file types?

Tags
beginners, file, grep, specific

 

 
Thread Tools Search this Thread
# 1  
Old 02-12-2008
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?
# 2  
Old 02-12-2008
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.
# 3  
Old 02-13-2008
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 02-18-2008
Thanks agn, that worked.
 

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep a log file starting from a specific time to the end of file erin00 Shell Programming and Scripting 3 08-14-2018 03:47 PM
Copying specific file types to specific folders Mr_Keystrokes Shell Programming and Scripting 8 03-06-2018 04:46 PM
Help with Grep Specific Date From One File Into A New One DennisG34 UNIX for Beginners Questions & Answers 3 02-21-2018 11:28 AM
Using grep to select specific patterns in text file? steezuschrist96 UNIX for Beginners Questions & Answers 4 09-30-2016 07:09 PM
Grep in a specific file in an archive Subbeh Shell Programming and Scripting 1 06-13-2014 10:50 AM
Recursive grep with only certain types of files cokedude UNIX for Advanced & Expert Users 5 01-20-2014 04:45 PM
How to grep an empty line in a specific column of a file? Ravi Tej Shell Programming and Scripting 7 01-09-2013 02:59 AM
Help with using different types of GREP SilvarHawke Homework & Coursework Questions 11 11-29-2011 08:08 AM
grep specific ipaddress from a file tbd UNIX for Dummies Questions & Answers 1 11-20-2011 07:02 PM
Grep from specific column in one file based on another file [Please help!] Zoho UNIX for Dummies Questions & Answers 2 07-15-2011 08:31 PM
Help with grep at specific field of a file techmoris Shell Programming and Scripting 7 10-21-2010 12:21 PM
grep a specific line from a file Max89 Shell Programming and Scripting 4 11-24-2009 01:31 PM
retrieving specific lines from a file - can I use grep ? hcclnoodles Shell Programming and Scripting 9 09-23-2008 07:45 AM
grep on specific line of the file rider29 Shell Programming and Scripting 4 05-29-2008 10:57 AM
Grep for NULL for a specific field in a unix file sureshg_sampat UNIX for Dummies Questions & Answers 5 11-24-2006 09:21 AM
All times are GMT -4. The time now is 05:24 PM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.