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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-19-2007, 03:40 AM
|
#1
|
Member
Registered: May 2005
Location: India
Distribution: FC11, Debian/Ubuntu, RHEL, Solaris, AIX, HP-UX
Posts: 161
Rep:
|
sed help needed
I want to remove USERID from my /etc/xinetd.conf in 300 servers and for that I want to use "sed" through a script.
The file
Code:
defaults
{
instances = 60
log_type = SYSLOG authpriv
log_on_success = PID HOST USERID EXIT DURATION
log_on_failure = HOST USERID ATTEMPT
cps = 25 30
}
includedir /etc/xinetd.d
Should look like ...
Code:
defaults
{
instances = 60
log_type = SYSLOG authpriv
log_on_success = PID HOST EXIT DURATION
log_on_failure = HOST ATTEMPT
cps = 25 30
}
includedir /etc/xinetd.d
I used
sed 's/USERID //' /etc/xinetd.conf
But it is showing me correct output in the screen, but it is not writing to the file.
|
|
|
11-19-2007, 03:59 AM
|
#2
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
it won't write it to the file, it's not meant to. you would save that as a temp file and replace it afterwards with sed. yo could use ex instead to directly modify the file rather than editing a stream on the fly.
|
|
|
11-19-2007, 04:03 AM
|
#3
|
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
GNU sed has an inplace option to perform the edit on the file directly.
sed -i '/log_on_success/s/USERID //' /etc/xinetd.conf
|
|
|
11-19-2007, 04:14 AM
|
#4
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
ah, duly noted...
|
|
|
11-19-2007, 04:16 AM
|
#5
|
Member
Registered: May 2005
Location: India
Distribution: FC11, Debian/Ubuntu, RHEL, Solaris, AIX, HP-UX
Posts: 161
Original Poster
Rep:
|
jschiwal,
You are the One!!
I just did the same with
sed -i 's/USERID //' /etc/xinetd.conf
and it does what I wanted to to. e.i, remove the USERID from muliple lines too.
Thanks a lot.
|
|
|
11-19-2007, 08:14 AM
|
#6
|
Member
Registered: Jun 2005
Location: Aylesbury UK
Distribution: Red Hat enterprise linux 6
Posts: 101
Rep:
|
Quote:
Originally Posted by acid_kewpie
it won't write it to the file, it's not meant to. you would save that as a temp file and replace it afterwards with sed. yo could use ex instead to directly modify the file rather than editing a stream on the fly.
|
Does this mean that if you know what you want to replace, there is a utility 'ex' which is better than 'sed' ?
|
|
|
11-19-2007, 08:22 AM
|
#7
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
well ex is a command line version of vi, which you *should* know intimately already. the -i option clearly does the job too though, so it's down to user comfort only...
|
|
|
11-19-2007, 08:24 AM
|
#8
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
Quote:
Originally Posted by pppaaarrrkkk
Does this mean that if you know what you want to replace, there is a utility 'ex' which is better than 'sed' ?
|
"ex" invokes a special mode of the VIM editor. I don't know VIM, but I assume it must have a search and replace function. (Search and replace is of course one of the main things SED does).
"better"? I would say SED is probably more powerful---but an editor might be easier to use
|
|
|
11-19-2007, 08:33 AM
|
#9
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
you don't know vi? shame on you, i thought you were better than that  I actually took a long time to try vi, stuck firm with pico / nano for about 5 years, but vi clearly is totally awesome.
|
|
|
All times are GMT -5. The time now is 04:55 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|