That's one of the coolest things I learned in this list! I wasn't aware that sed took the first character and used it as a delimiter. I wonder why it's so common to use / then. Most of the unix for beginners books and tutorials give the notion that it's part of sed's syntax to substitute /'es. thanks for the cool tip... Lior
On Tue, 8 Mar 2005 16:56:07 +0200, Tzafrir Cohen <[EMAIL PROTECTED]> wrote: > 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] > > -- Peace Love and Penguins - Lior Kesos ================================================================= 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]