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''

1 Answer 1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .