I have a namelist containing inputs for simulations. I have to change the path of some variables using bash. The text file has the following value that I would like to change:
opt_path = '/home/gle/test_workflow',
I would like to replace the value of opt_path with cat and sed, and I tried the following but it doesn't work:
new_path=/my/new/path
cat namelist.wps | sed "s/^opt_path.*/opt_path = '${new_path}'/g"
it returns the following error:
sed: -e expression #1, char 29: unknown option to `s'
Someone has an idea?
EDIT: After some trials, the following code worked.
#!/bin/bash
new_path=/my/new/path
cat namelist.wps | sed "s|^.* opt_path =.*$| opt_path = '${new_path}', |g" > namelist.wps.new
Though it is working only with one whitespace between = character. How can I specify any number of whitespace between opt_path, =, and the value?
Thanks, Greg