LinuxQuestions.org
Help answer threads with 0 replies.
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 11-19-2007, 03:40 AM   #1
avijitp
Member
 
Registered: May 2005
Location: India
Distribution: FC11, Debian/Ubuntu, RHEL, Solaris, AIX, HP-UX
Posts: 161

Rep: Reputation: 32
Unhappy 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.
 
Old 11-19-2007, 03:59 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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.
 
Old 11-19-2007, 04:03 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 683Reputation: 683Reputation: 683Reputation: 683Reputation: 683Reputation: 683
GNU sed has an inplace option to perform the edit on the file directly.
sed -i '/log_on_success/s/USERID //' /etc/xinetd.conf
 
Old 11-19-2007, 04:14 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
ah, duly noted...
 
Old 11-19-2007, 04:16 AM   #5
avijitp
Member
 
Registered: May 2005
Location: India
Distribution: FC11, Debian/Ubuntu, RHEL, Solaris, AIX, HP-UX
Posts: 161

Original Poster
Rep: Reputation: 32
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.
 
Old 11-19-2007, 08:14 AM   #6
pppaaarrrkkk
Member
 
Registered: Jun 2005
Location: Aylesbury UK
Distribution: Red Hat enterprise linux 6
Posts: 101

Rep: Reputation: 15
Quote:
Originally Posted by acid_kewpie View Post
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' ?
 
Old 11-19-2007, 08:22 AM   #7
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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...
 
Old 11-19-2007, 08:24 AM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by pppaaarrrkkk View Post
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
 
Old 11-19-2007, 08:33 AM   #9
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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.
 
  


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
awk or sed help needed cmontr Programming 42 11-02-2007 11:43 PM
SED help needed DriveMeCrazy Linux - General 2 11-20-2006 10:04 PM
Help on sed and perl needed. cash_05 Programming 7 09-03-2005 04:33 PM
sed regular expression help needed Dew Linux - Newbie 1 03-30-2005 02:59 PM
Sed/Awk command help needed. farmerjoe Programming 3 03-02-2005 11:13 AM

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

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