Find and replace

Hi,

I have a variable which holds the below value:

echo $FROM_DIR
/fsg/fgldevu/fs_ne/inst/FGLDEVU_01/logs/appl/conc/out/o14946708.out

I want to change the value in the variable as below:
out/o to be replaced with log/l
.out to be replaced with .req
The desired output should look like this

echo $TO_DIR
/fsg/fgldevu/fs_ne/inst/FGLDEVU_01/logs/appl/conc/log/l14946708.req

Can anyone pls help me how to replace this inside a variable

Prasanna

Any attempts / ideas / thoughts from your side?

Hi RudiC,

I tried with echo ${FROM_DIR//out/log}
But I cant put echo ${FROM_DIR/out/o/log/l} as it is not working

My search string as well as replace string has a / in between

Not bad an approach. Try to escape the / inside the string.

1 Like

Thanks: Now I have done it in 2 steps:

TO_DIR=${FROM_DIR/"out/o"/"log/l"}
TO_DIR=${TO_DIR/".out"/".req"}

Can it be done in a simpler way?

Not to my knowledge. shells need this detour.

1 Like