LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-06-2011, 02:23 PM   #1
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Rep: Reputation: 16
Question Add Line to a File ( 3rd line)


Hi...
going back to my earlier post "Last digit minus ONE", when i get a Ip addresse with minus 1 ($ip), i need to add the new Ip address ($ip) to resolv.conf of that system.
so from resolve.conf:
Code:
# /etc/resolv.conf .......
domain mydomain.ca
nameserver 11.21.36.98
nameserver 11.21.37.98
nameserver 11.21.38.98
I need to make it like:
Code:
# /etc/resolv.conf
domain mydomain.ca
nameserver $ip
nameserver 11.21.36.98
nameserver 11.21.37.98
nameserver 11.21.38.98
.........  ...........
.........  ...........
.........  ...........
tried with sed

Code:
sed 'nameserver $ip/domain/G' -f /etc/resolv.conf
but not able to get it.

any better way....
thanks
 
Old 04-06-2011, 02:32 PM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
You could do it like so:
Code:
cat /etc/resolv.conf | sed -e '3 i $ip' > /etc/resolv.conf.new
Of course you need to modify that.....
Hope that helps!

Cheers,

Josh
 
1 members found this post helpful.
Old 04-06-2011, 03:55 PM   #3
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
I'm getting fed up with people referring to earlier posts without a link or summary.

Either summarise it or link to it. Don't assume we're following your every word !
 
Old 04-06-2011, 03:58 PM   #4
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Quote:
Originally Posted by smoker View Post
I'm getting fed up with people referring to earlier posts without a link or summary.

Either summarise it or link to it. Don't assume we're following your every word !
Who's that to?
 
Old 04-06-2011, 05:16 PM   #5
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 716

Rep: Reputation: 112Reputation: 112
Quote:
Originally Posted by corp769 View Post
Who's that to?
probably your OP

Quote:
going back to my earlier post "Last digit minus ONE",
 
Old 04-06-2011, 07:11 PM   #6
kurumi
Member
 
Registered: Apr 2010
Posts: 228

Rep: Reputation: 53
Quote:
Originally Posted by NetRock View Post

tried with sed

Code:
sed 'nameserver $ip/domain/G' -f /etc/resolv.conf
but not able to get it.

any better way....
thanks

use double quotes so that your $ip variable can be interpolated. Same to some of the answers posted.
 
Old 04-07-2011, 07:17 AM   #7
NetRock
Member
 
Registered: Mar 2010
Posts: 134

Original Poster
Rep: Reputation: 16
Thank you for your replies.
 
  


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
access a file line by line, and check the length of each line. ddebbie90 Programming 1 02-13-2011 02:31 PM
[SOLVED] open two text files , read them line by line and update parameters of the 3rd file rastin_nz Programming 17 10-20-2010 07:10 PM
How can I read a file line by line and add it to a loop in another file? astroumut Linux - Newbie 7 08-24-2009 04:37 AM
php - Read file line by line and change a specific line. anrea Programming 2 01-28-2007 01:43 PM

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

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