I am using a while
loop to read a file line by line and, for example, if the file contains a line like:
ABC.///.AB_SWift_ABC
I need to replace it with
ABC.slashslashslash.AB_SWift_ABC
How can I do that with a Korn shell?
I am using a while
loop to read a file line by line and, for example, if the file contains a line like:
ABC.///.AB_SWift_ABC
I need to replace it with
ABC.slashslashslash.AB_SWift_ABC
How can I do that with a Korn shell?
If you are using bash
, you can use the variable substring replacement functionality.
>> a=ABC.///.AB_SWift_ABC >> echo $a ABC.///.AB_SWift_ABC >> echo ${a//\//slash} ABC.slashslashslash.AB_SWift_ABC
Why are you reading line by line? It would be quicker to simply run sed
on the file:
sed 's%/%slash%g'
If you must do it in Bash, then use the substitute shell parameter expansion:
${line//\//slash}
You mention backslashes but use forward slashes, which is confusing. If, perchance, you mean backslashes, then:
sed 's/\\/slash/g'
${lines//\\/slash}
In c
you can replace /
by slash
using bash command like
char cmd[]="sed -i 's|/|slash|g' file";
system(cmd);
So not require read file line by line.