LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-08-2018, 05:49 AM   #1
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
sed substitution doubles pattern


Instead of substituting the first pattern, it adds another ".host". I don't understand what I'm missing.

Code:
grep host /etc/varnish/default.vcl
Result:
Code:
.host = "172.31.108.183";
Code:
sed -r "s/(.host = \")[0-9]+.[0-9]+.[0-9]+.[0-9]+(\")/\1\192.10.10.10\2/}" /etc/varnish/default.vcl | grep host
Result:
Code:
.host = ".host = "92.10.10.10";

Last edited by vincix; 01-08-2018 at 06:28 AM.
 
Old 01-08-2018, 06:37 AM   #2
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
Never mind. I was actually trying to escape the first 1 of the "192" group and without realising it, I was actually making the pattern \1 reoccur.
 
Old 01-08-2018, 08:38 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,927

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
just a comment: . is a special char, you need to protect it: \. (if you want literal .)

Last edited by pan64; 01-08-2018 at 08:39 AM.
 
Old 01-08-2018, 08:42 AM   #4
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
Yes, I know, you're right. It means any one character.
 
  


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
[SOLVED] vi substitution question (or sed) l33y Linux - Newbie 8 08-20-2016 06:40 AM
Sed substitution gives error "sed: command garbled" gsai0205 Linux - Newbie 3 09-13-2013 09:01 AM
[SOLVED] Sed substitution using & linuxScriptGirl Linux - Newbie 9 03-17-2011 10:20 AM
SED - substitution carolflb Linux - Newbie 5 02-06-2010 12:20 AM
Pattern matching and substitution mailbox-1691 Linux - General 1 08-12-2009 08:27 AM

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

All times are GMT -5. The time now is 11:31 PM.

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