LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 03-21-2009, 10:50 PM   #1
treed
Member
 
Registered: Sep 2003
Posts: 45

Rep: Reputation: 15
Sed usage


I am trying to change the following line in the ldap.conf file using sed:
pam_filter host=orbit

So far my sed script from command line looks like the following:
1. sed -n 's/pam_filter host=orbit/pam_filter host=aiso-basic/g' ldap.conf

2. sed -n 's/(pam_filter\ host\=orbit)/(pam_filter\ host\=aiso\-basic)/g'


What I really want to do is
sed -n 's/pam_filter host=orbit/pam_filter host=`echo hostname`/g' ldap.conf

I tried escaping the space between filter and host. As well as the equal sign.

Any ideas anyone
 
Old 03-22-2009, 12:19 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,120

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Quote:
Originally Posted by treed View Post
Any ideas anyone
Well 3 (at least) come to mind:
- if you want to update the file use "-i"
- You probably want `hostname` rather than `echo hostname` - $(hostname) is better
- use double quotes rather than single
 
Old 03-22-2009, 02:51 AM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
awk
Code:
awk -F"=" '/pam_filter host/{$2="aiso-basic"}1' OFS="=" file
 
Old 03-22-2009, 04:23 PM   #4
treed
Member
 
Registered: Sep 2003
Posts: 45

Original Poster
Rep: Reputation: 15
Problem Solved

I did the following in case anyone wants to know:
sed -i 's/pam_filter host=orbit/pam_filter host=aiso-basic/g' ldap.conf

Still working on echo hostname portion.


I tried the awk command but did not get that to work. I may have missed something there.
 
Old 03-22-2009, 05:39 PM   #5
treed
Member
 
Registered: Sep 2003
Posts: 45

Original Poster
Rep: Reputation: 15
Problem Solved with echo

sed -i 's/pam_filter host=someserver/pam_filter host='`hostname|cut -f1 -d'.'`'/g' filename

Please note those are single quotes and inside those single quotes are back ticks
 
  


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 newline usage question -- I think sadarax Linux - General 3 02-18-2006 11:50 PM
sed usage(only repace one occurance) feetyouwell Linux - Software 7 01-31-2005 02:25 PM
sed usage(only repace one occurance) feetyouwell Linux - Software 2 01-31-2005 04:08 AM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

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

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