Fastest way to filter a string I'm working on a script that reads the header of some files (medical images), filters the data and then creates a file directory based on that data.
But there are millions of images and I need to make it faster in a task.
After reading the image, the script creates a block of information that I need to filter, swap the letters accented by normal letters, swap any space for an underline, and then delete any character other than "AZ, AZ, 0-9,_)( ][-".
At the moment I use the SED and Tr commands as shown below, Is there a faster way to do this ? TIA

BLOCK=$( command to read the images ) 
FILTER=$( echo $BLOCK | tr 'ÁÉÍÓÚáéíóúçÇ ^\' 'AEIOUaeioucC_:' | sed -e 's/[^A-_a-z0-9() -]//g' )
This does not address the "faster way" part of the question: more of a code review


make sure to quote your variables: echo "$BLOCK"
"delete any character other than "AZ, AZ, 0-9,_)( ][-" ->

tr -dc '][:alnum:]_)( [-'


where -d means "delete" and -c mean "the complement of the given set". [:alnum:] is a character class matching letters and numbers.