On Tue, Mar 08, 2005 at 04:01:52PM +0200, Michael Green wrote:
> how one can cut out a portion of a line using sed?
> 
> I have this (from /etc/sudoers):
>  %nice  ALL=NOPASSWD: /bin/nice,/usr/bin/renice
> 
> and I want to remove /bin/nice retaining all the rest.
> 
> I've developed this:
> 
> math02-lx:/root->1035# sed -n -e '/renice/s/\(.*\): \(.*\),\(.*\)/\1:
> \3/p' /etc/sudoers
>  %nice  ALL=NOPASSWD: /usr/bin/renice
> math02-lx:/root->1036#
> 
> Is there more elegant way of doing this using sed?

Use another character instead of '/' as a delimiter for the 's' command
and you won't have to do escaping.

e.g: 

  $ echo '%nice  ALL=NOPASSWD: /bin/nice,/usr/bin/renice' |sed -e 
's|/bin/nice,||'
  %nice  ALL=NOPASSWD: /usr/bin/renice

Here I used '|' where '/' is normally used.

So basically you could use something like:

  sed -ie  -e 's|/bin/nice,||' /etc/sudoers

Or, following the recomendations in that file, something like:

  EDITOR="sed -ie  -e 's|/bin/nice,||'" visudo 

(UNTESTED)

-- 
Tzafrir Cohen         | New signature for new address and  |  VIM is
http://tzafrir.org.il | new homepage                       | a Mutt's  
[EMAIL PROTECTED] |                                    |  best
ICQ# 16849755         | Space reserved for other protocols | friend

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to