LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Replace /1/ to /2/ using sed (https://www.linuxquestions.org/questions/linux-newbie-8/replace-1-to-2-using-sed-4175606700/)

Asoo 05-26-2017 05:46 AM

Replace /1/ to /2/ using sed
 
Greetings!

I would like to replace a number along with '/' to a new number but I couldn't figure it out.

I have tried the following:

Code:

sed -i "s/'/9///8/'/g" test.sh
There are other numbers which should be unchanged, except the matched patter ones.

Thanks in advance!

pan64 05-26-2017 05:50 AM

you need to use another delimiter, for example ! instead of /

Asoo 05-26-2017 05:52 AM

Is it not possible to use "/" as delimiter?

Turbocapitalist 05-26-2017 05:52 AM

Try using something besides a slash for your replacement delimiter so it's easier to read and that so you won't have to escape the slash you are searching for. sed does not care what it is as long as you use three of a kind.

Code:

sed -e 's|/9|/8|g;'
See:

Code:

man sed
However, you might want to think out the logic of how you are going to replace all 10 digits one at a time. You'll probably need a non-digit place holder for one of them.

pan64 05-26-2017 05:54 AM

Quote:

Originally Posted by Asoo (Post 5715405)
Is it not possible to use "/" as delimiter?

It is definitely possible, in that case you need to protect all the / chars using \

Asoo 05-26-2017 05:56 AM

Okay, I will do as suggested. Thank you.


All times are GMT -5. The time now is 09:55 PM.