The above script reads for a physical path from allpath.txt . It then looks for all files except .logs & .class files using the find command find "$startdir" -type f \( ! -name "*.log*" ! -name "*.class*" \) -print .
Note: the find command above is instant if i fire it as a separate command from the bash shell on that directory location. Takes less than 2 secs to list all the files.
For each file found it searches for all the "search strings" mentioned in the alter.txt file while IFS= read -r var and replaces it with the corresponding text (this part of the code i have not shared considering not necessary)
For a folder 4GB in size it take around 25 mins to complete.
Can you help me optimize the script so it completes in less time.
The entire logic and structure of that script seems suboptimal. For every file found, you (re)open "alter.txt", read every single line, invoke awk twice and - I'm guessing based on your other threads - run something like sed to do the replacements.
Depending on the found files' count this IS going to be lengthy.
I'm not talking of improving the innermost loop here - although there is quite some potential.
Why don't you leave the looping to one single instance of e.g. awk ?
Create a list of all file candidates ( find can have several paths as starting points) and run awk , first reading all the search/replacement pairs, and then working those on all files presented.
Your post#3 is 4 times faster but has more output lines, so I guess something goes wrong.
Try my optimization with your post#1; it is 10 times faster and produces indentical output.