How do I grep in specific file types?

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How do I grep in specific file types?
# 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
grep $pattern *.log

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

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


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

# 4  
Old 02-18-2008
Thanks agn, that worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Searching for file types by count in specific folder in RHEL 6

So I'm trying to search for the top 10 or 15 items under a directory by file type. I want to run a command on a directory and get something like the following: Example of expected output.. .PDF: 100, .txt: 95, .word: 80.. What would be the best way of going about this? I've searched around... (2 Replies)
Discussion started by: shackle101
2 Replies

2. Shell Programming and Scripting

Grep a log file starting from a specific time to the end of file

I have a log file which have a date and time at the start of every line. I need to search the log file starting from a specific time to the end of file. For example: Starting point: July 29 2018 21:00:00 End point : end of file My concern is what if the pattern of `July 29 2018 21:00:00`... (3 Replies)
Discussion started by: erin00
3 Replies

3. Shell Programming and Scripting

Copying specific file types to specific folders

I am trying to write a script that cycles through a folder containing many folders and when inside each one it's supposed to copy all the .fna.gz files to a folder elsewhere if the file and the respective folder have the same name. for fldr in /home/playground/genomes/* ; do find .... (8 Replies)
Discussion started by: Mr_Keystrokes
8 Replies

4. UNIX for Beginners Questions & Answers

Help with Grep Specific Date From One File Into A New One

Hello All, First post, don't know much about Linux/Unix, but I need some help. Normally, I do grep 'what I'm searching for' FILE > file.txt so I can pull data from one file, and put it into a new one. The issue I am having is with specific dates, since the date field is 4, and it appears... (3 Replies)
Discussion started by: DennisG34
3 Replies

5. Shell Programming and Scripting

Grep in a specific file in an archive

Hi all, I need to do a grep in a specific file inside multiple (tar.gz) archives. I know zgrep can grep in an archive, but as far as I know, I can't supply a specific filename from inside the archive to grep in. Is there any other way do to this, besides extracting it and then... (1 Reply)
Discussion started by: Subbeh
1 Replies

6. UNIX for Advanced & Expert Users

Recursive grep with only certain types of files

Can I please have some ideas on how to do a recursive grep with certain types of files? The file types I want to use are *.c and *.java. I know this normally works with all files. grep -riI 'scanner' /home/bob/ 2>/dev/null Just not sure how to get it to work *.c and *.java files. (5 Replies)
Discussion started by: cokedude
5 Replies

7. Homework & Coursework Questions

Help with using different types of GREP

1. The problem statement, all variables and given/known data: Hey there, I'm brand new to using Unix as I just started a course on it in my University, and I currently working through a worksheet which focuses on the many commands and methods of GREP (I'm working through the terminal command... (11 Replies)
Discussion started by: SilvarHawke
11 Replies

8. UNIX for Dummies Questions & Answers

grep specific ipaddress from a file

All, Iam new to unix and i have 1 requirement, can anyone help me please I have provided the file below, i will be having similar files in 100+clients systems. i want to check the the ip address "" and if it is present then i should get a mail alert, if the ip address is not... (1 Reply)
Discussion started by: tbd
1 Replies

9. Shell Programming and Scripting

Help with grep at specific field of a file

hi, I would like to search for a specific string at a specific line in a file and would like to know the count of it. eg: samp.txt ABC 1234 BELL HNZ 4567 RING NNN 5673 BELL Please help with the command to find the count of BELL in the above file samp.txt at the specific line 10 with... (7 Replies)
Discussion started by: techmoris
7 Replies

10. Shell Programming and Scripting

grep on specific line of the file

Hi, how can we search for a word (with case ignore )on specific line numbers ex: Awk /^regEX/ with condition on first line or second line Awk/^ regex1/ on line 1 Awk /^regEX2/ on line 3 thanks in advance (4 Replies)
Discussion started by: rider29
4 Replies
Login or Register to Ask a Question