Loop certain code to all files within directory

Hi all,

Can somebody help me with this problem pls.

I need to extract one specific line from each files in a folder and put
the all lines extracted in a unique output file in the following format.

line extracted, respective name of file, date of file.

I�m, trying the part to extract the desired line with

awk '/Category/ {getline; print}' infile.txt

But I dont know how to do a loop over all files and send all lines
to one outfile.txt with the format desired.

Example:
If the line extracted from one specific file with

awk '/Category/ {getline; print }' infile.txt

is "District school", the desire result would be:

District school,  file date,  file name

Thanks in advance for any help

Hi cg,

You can loop through the files inside a directory like this:

FLDR="."
cd $FLDR
find . ! -name . -prune -type f | while read x; do
   # this will print the filename
  #echo $x

  # To get the date
  #ls -lt $x | awk '{print $6" "$7" "$8}' 
  # If the file is older than 6 months (not sure though), this will include the year. If not, this will include the time

  # What you want maybe like this: 
  found=`awk '/Category/ {getline; print }' "$x"`
  [ "$found" != "" ] && echo "$found,$x,"`ls -lt $x | awk '{print $6" "$7" "$8}'`
done
#!/usr/bin/perl
@files=glob("*.txt");
open FH,">out.txt";
foreach(@files){
	open F,"<$_";
	my $file=$_;
	while(<F>){
		print FH $file," line $.: ",$_ if /Toyota/;
	}
	close F;
}
close FH;

Hi anghel and summer_cherry,

:DSimply perfect!!!, exactly what I need.

Very appreciated your always kindly help.

Best regards