LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-02-2016, 02:21 AM   #1
TashiDuks
Member
 
Registered: Sep 2010
Posts: 54

Rep: Reputation: 0
Any suggestion for my 'sed' syntax? I am getting Error


I am trying to update a configuration file value. My configuration has got following value:
Code:
"mailhost": ["20.20.20.1", 25],
I want to change the value 20.20.20.1 only excluding rest characters to something to 30.30.30.1. I have following script lines which I came up with:
Code:
sudo sed -i 's/\("mailhost": ["\).*\(, 25]\)/\1 "'30.30.30.1'" \2/g' mymy.conf
I get "sed: -e expression #1, char 52: invalid reference \2 on `s' command's RHS" message." syntax error message.

Can anyone help me please?

I also tried using following syntax (got by searching in google) but still the error message is same.
Syantx example(GOOGLE):
Code:
 sed 's/\(*string1\).*\(string3.*\)/\1string2\2/' mymy.txt
The syntax which i used
Code:
 sudo sed 's/\(*"mailhost": ["\).*\(", 25],.*\)/\1"30.30.30.1"\2/' mymy.conf
Thanks

Last edited by TashiDuks; 12-02-2016 at 02:39 AM.
 
Old 12-02-2016, 02:48 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
You have only shown part of the line so my answer is based only on this portion and may fail if the line has other data that my regex will match:
Code:
sed '/mailhost/s/[0-9][^"]*/30.30.30.1/'
As to your own solution, grouping heer would seem to make the solution more complicated and adding 'g' implies you want to perform more than a single change, should they exist.

So without seeing more of the data, my current solution is my suggestion.
 
Old 12-02-2016, 03:02 AM   #3
TashiDuks
Member
 
Registered: Sep 2010
Posts: 54

Original Poster
Rep: Reputation: 0
@grail ... Thanks mate. You made my day, it worked.

I Used this:

Code:
sed -i '/mailhost/s/[0-9][^"]*/30.30.30.1/' mymy.txt

Tashi
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Syntax Question StorageDon Programming 5 06-09-2016 12:33 AM
[SOLVED] sed syntax mreff555 Linux - Newbie 2 08-02-2012 08:34 AM
script.pl with sed shell calls: sh error syntax error near unexpected token `(' MMaddoxx Programming 7 11-24-2011 08:00 AM
[SOLVED] sed between command syntax tnrooster Linux - Software 9 01-31-2011 08:08 PM
Another SED Syntax Question... stlouis Programming 3 01-17-2008 08:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:36 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