I have a string like string1="app/local/home/usr/data/"
that I want to replace with string2="app2/local/home/blablabla"
. How can I replace the string1
with string2
? I tried using sed
which did not work.
Asked
Active
Viewed 37 times
-2

Jonathan Leffler
- 730,956
- 141
- 904
- 1,278

cheenubear
- 11
- 2
-
2Take note that: 1) the separator for the `s` ed command is *not* `/`, it is more or less arbitrary and 2) the separator can be escaped with `\\`. – Jan Hudec May 29 '17 at 13:03
-
Possible duplicate of [How to replace a path with another path in sed?](https://stackoverflow.com/questions/12061410/how-to-replace-a-path-with-another-path-in-sed) – Benjamin W. May 29 '17 at 15:22
1 Answers
0
This script would give you the best solution , I think..
#!/bin/sh
string1="app/local/home/usr/data/";
text=$(dirname $(dirname $string1));
echo $text|sed "s/app/app2/"|
sed -e "s/(.*\)/\1\/blahblah/"
This gives output after executing the script.sh
app2/local/home/blahblah

Harini
- 551
- 5
- 18