LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-26-2017, 05:46 AM   #1
Asoo
Member
 
Registered: Apr 2017
Posts: 33

Rep: Reputation: Disabled
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!
 
Old 05-26-2017, 05:50 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
you need to use another delimiter, for example ! instead of /
 
Old 05-26-2017, 05:52 AM   #3
Asoo
Member
 
Registered: Apr 2017
Posts: 33

Original Poster
Rep: Reputation: Disabled
Is it not possible to use "/" as delimiter?
 
Old 05-26-2017, 05:52 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,309
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
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.
 
1 members found this post helpful.
Old 05-26-2017, 05:54 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
Quote:
Originally Posted by Asoo View Post
Is it not possible to use "/" as delimiter?
It is definitely possible, in that case you need to protect all the / chars using \
 
1 members found this post helpful.
Old 05-26-2017, 05:56 AM   #6
Asoo
Member
 
Registered: Apr 2017
Posts: 33

Original Poster
Rep: Reputation: Disabled
Okay, I will do as suggested. Thank you.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed replace question aaadougford Linux - Newbie 3 01-31-2014 05:21 PM
[SOLVED] Sed replace Help replace for (<a> guessity Linux - Newbie 1 11-18-2011 09:05 AM
How do I replace ' with sed.... @ngelot Linux - Newbie 2 11-02-2007 07:04 PM
SED - replace / insert furquan Programming 5 03-01-2006 06:58 PM
[sed] replace string? chuanyung Programming 3 03-11-2004 08:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration