I am using grep to catch a part of many files, which has name 001.log, 002.log, 003.log ....I need to save the grep as a different file grep -A3406 -P 'Molecular' *.log And to output the grep in files with the name 001a.log, 002a.log, 003a.log ...
How to save the grep o many files
bash;shell script
Just redirect the grep's output to a file:grep -A3406 -P 'Molecular' *.log > new_fileYou can then process the new file and split it on the file name change (or just pipe the output to the splitting script). More details would be needed to give a working example.Or, process the files one by one (would be a bit slower):for file in *.log ; do    grep -A3406 -P 'Molecular' $file > ${file%.log}a.logdoneAlso, you don't need -P for a simple regex like Molecular.