search information in multiple files and save in new files

hi everyone,

im stuck in here with shell :slight_smile: can you help me??

i have a directory with alot files (genbank files ... all ended in .gbk ) more than 1000 for sure ... and i want to read each one of them and search for some information and if i found the right one i save in new file with new name.

i already get try for loops and no sucess :frowning:

well for search the information i get it right :

awk 'BEGIN{RS="LOCUS"}/Equinodermata/{print "LOCUS"$0}'

i only cant read each file and save in news!

please help me :slight_smile: i will give you a candy :wink:

awk 'BEGIN{RS="LOCUS"}/Equinodermata/{print "LOCUS"$0}' *.gbk >> new_file

sorry dont work out :frowning:

and its for all files .gbk that i found Equinodermata inside save in different file not all together but its ok ... thanks for your help :wink:

Should this new file be in the same directory as the old one?

well this is not really important ... but yes could be in same directory

Try:

for file in *.gbk; do
  awk 'BEGIN{RS="LOCUS"}/Equinodermata/{print "LOCUS"$0}' $file > new_$file
done
awk 'BEGIN{RS="LOCUS"}/Equinodermata/{print "LOCUS"$0 > FILENAME"_found"}' *gbk

your search patterns if found in a file say something.gbk, will be written into a new unique file something.gbk_found