0

I have a string that I want to remplace in a script to put the actual path of the file so: my issue is that the string has special characters inside

Dir=pwd
old=simulationfoam = OpenFOAMReader(registrationName='simulation.foam', FileName='path/simulation.foam')
new=simulationfoam = OpenFOAMReader(registrationName='simulation.foam', FileName='${Dir}/simulation.foam')

My first attend was to signle quote everything:

old='simulationfoam = OpenFOAMReader(registrationName='simulation.foam', FileName='path/simulation.foam')'
new='simulationfoam = OpenFOAMReader(registrationName='simulation.foam', FileName='${Dir}/simulation.foam')'

but the issue persisted after looking in the web i found this :https://stackoverflow.com/questions/15783701/which-characters-need-to-be-escaped-when-using-bash where it mentionned that I should scape the ' with 'backslash' so I remplace the internal ' of the string with 'backslash''

New contributor
otaolafr is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
0

I solved by using | instead of / in the seq line so:

sed -i "19s|simulationfoam = OpenFOAMReader(registrationName='simulation.foam', FileName='PATH/simulation.foam')|simulationfoam = OpenFOAMReader(registrationName='simulation.foam', FileName='$(pwd)/simulation.foam')|" ./code.py
New contributor
otaolafr is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

otaolafr is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.