I have a requirement to update a variable across multiple files/sub-directories. The variable to be replaced starts with the same 6 characters, everything after this is random. I will use these first 6 characters as the pattern to find/replace on. I will replace the random characters following with a sequential variable.
I'm not sure what utility is best to achieve this but I imagine sed in some kind of loop? I'm struggling to visualise how best to achieve this. I imagine it could be done with something like;
#!/bin/bash i=0 grep -r '/parent/sub/' -e 'pattern' | while read line do sed 's/pattern*/pattern$i/g' ((i++)) done
My first issue is I don't know if sed can be used this way, secondly as it's nested in the loop how do can I feed it the required lines from the grep command (or is there a better method than grep to be used here?)