I'm looking to automate a process whereby a part of the filename is what is used to replace a value inside the file itself.
Currently I use a manual process that looks like this:
get the orgname manually
$ grep -o orgname......... *2017-04* |uniq ... uname=123456&**orgname=ABC5678**&userType=PERSISTENT&userLoginName=someusername&eventType=FAILED_LOGIN_ATTEMPT&timeOfOccurrence=2017-03-12%2016%3A49%3A36
Then replace orgname with new name
$ sed -i 's/ABC1234/5678/g' `*`5678`*` ; sed -i 's/DEF2345/6789/g' `*`6789`*`; sed -i etc...
The final result would look like this:
The files are named like this:
Whatever is after orgname= needs to change from ABC5678 to whatever comes after Lxxxx, only in files with the same xxxx in its filename.
I'm having a hard time getting my head around how to extract that number from the file name and using it in a
sed. There are hundreds of files (each with their own date) and 6 different number pairs to work with. I'm hoping to write a bash script that does this all at once.
I was trying to use
grep -P combined with putting that into some sort of variable and using
sed but maybe there is a better/easier way?
Let me know if there are any additional questions.