0

Could you please help me out?

I have multiple files in a folder contain string {env} in a filename , I need to replace {env} with value of current environment?

so I got the current environment details as :

env_details = "dv"

and now I was to change filename , below folder have multiple files:

/home/harshit/cofig/*

cat_{env}.config

mbr_details_{env}.config

acc_num_{env}.config .

....

now I want to replace {env} with "dv" as below:

/home/harshit/cofig/*

cat_dv.config

mbr_details_dv.config

acc_num_dv.config

....

could anyone please help me out how to achieve this ?

harsh
  • 17
  • 9
  • https://www.google.com/search?q=How+to+rename+string+in+multiple+filename `mv command since it will move the files to different folder?` That's not necessarily true. `mv` can move a file to the same folder. – KamilCuk Apr 14 '20 at 07:48
  • This example is useful if we have replacing text at start .. but my replacing text {env} is at last . this is not working. for file in *.conf ; do mv $file $(file//{env}//$env_details} ; done – harsh Apr 14 '20 at 08:26
  • Escape "{" and "}" in ```{env}``` or assign ```{env}``` to a variable first. ```PATTERN="{env}"; for file in *; do mv "$file" "${file/$PATTERN/$env_details}"; done``` – clpgr Apr 14 '20 at 08:45

0 Answers0