I have several scripts that edit template text files, by removing a "tag" and replacing it with e.g. a number. To do this I use the
sed -i command. However, I have an issue with write/read times on the server where I execute the scripts, making the scripts take a long time to run, since the sed -i command writes a temporary file to disk for every execution.
Is there an alternative approach that I could use, where a temporary file is not written to disk for every single replacement? Can the text file be edited in the memory and only written once all the replacements have been executed, or could I stack several replacements into the same sed command?
To clarify, the script is of the following form:
input=shiftLeft.txt while IFS= read -r line do sed -i "s/install, element = $line, at=/install, element = $line, at= -0.001 +/g" processedFiles/layoutDB.seq done < "$input" That is, I read values from one text file, and then I do some changes in another text file depending on these values. This is done repeatedly for a large number of values.
ed?sed -ion the same file. Yes, you should add all the-ecommands you want into a singlesedinvocation (or even into asedscript file - seesed -f).edwould potentially also use temporary files.sed -idoes not take a long time to run due to creating temporary files. It takes a long time to run because you're executing it in a tight loop. Please show what you are actually doing.