Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursive search using awk command

I have 100 log files and I want awk to search for a given pattern between a given timestamp recursively. Log files look something like this

2010-03-24 07:00:01 ZZZZC941948879 RUFFLES 222.222.222.222 GET / - 80 - 220.181.7.113 HTTP/1.1       
2010-03-24 07:00:23 ZZZZC941948879 RUFFLES 222.222.222.222 GET 

Code is

 awk -v "b=$date1" -v "e=$date2" '$1 >= b && $1 <= e' log.txt > output
 grep -i "21things" output

I am able to search for the pattern but for single file only. Is it possible using awk command to search recursively?

Thanks for the help..!!

like image 288
atul329 Avatar asked Dec 15 '25 07:12

atul329


1 Answers

You can use find command to course through all files recursively in a directory and pass the file into awk. The following will show all the files where a match occurred. Change the <PATTERN> with required:

find . -type f -exec awk '/<PATTERN>/{print FILENAME; nextfile}' '{}' \;

The following will print out all lines matched along with filename:

find . -type f -exec awk '/<PATTERN>/{print FILENAME ":\t" $0;}' '{}' \;
like image 56
Haribk Avatar answered Dec 16 '25 21:12

Haribk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!