How to process select list of files and output to the same file?

Hi,

I've a list of files

ac_info.tps, subscription_array.tps, .......and many other files

one of the file, bin_range_list.tps has the following content

CREATE OR REPLACE TYPE "BIN_RANGE_LIST"                                          AS TABLE OF BIN_RANGE_ELEM;
/
grant execute on BIN_RANGE_LIST to SUPERB_TXN;




how do I extract the portion on grant.and place result in a file called bin_range_list_to_superb_txn?

grant execute on BIN_RANGE_LIST to SUPERB_TXN;

understand that for one file we can do the following:

cat bin_range_list | grep "grant" > bin_range_list_to_superb_txn

but how do I repeat the above process for a list of files?

thanks

If you have grep supporting the -h option:

grep -h grant *.tps > bin_range_list_to_superb_txn

Or with awk:

awk 'index($0,"grant")' *.tps > bin_range_list_to_superb_txn

Hi elixir sinari,

I have a list of files and the output for each file is different,

bc_attribute_rec.tps,
bc_attribute_update.tps
bc_attribute_update_arr.tps

output of the files

bc_attribute_rec_to_txn.tps,
bc_attribute_update_to_txn.tps
bc_attribute_update_arr_to_txn.tps

so how do I achieve it?

thanks

Run this in the directory having ONLY the input .tps files:

for i in *.tps
do
 grep grant "$i" > "${i%.*}_to_txn.tps"
done

Are we dealing with moving targets or sloppy wording? In post#1, the output file should be bin_range_list_to_superb_txn , in post#3 it was sth_to_txn.tps , sth being the input file name with its suffix deleted.
Guessing that the file name addendum should be the user name granted to, I'd propose

$ awk '/grant/ {fn=FILENAME"_"$(NF-1)"_"$NF; gsub(/\.tps|;/,"",fn); print > fn}' *.tps