-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Willie Wong wrote:

>On Sun, Nov 06, 2005 at 09:03:01PM -0800, gentuxx wrote:
>
>>sed -n '/^CLOCK=/s/^\(CLOCK=".*"\).*$/\1/p /etc/conf.d/clock
>>
>
>Ah, yes, I misunderstood the OP. I thought he didn't want the lines
>with trailing comments at all.
>

He didn't really make that clear in his first post.  ;-)

>But is it necessary to give the address for an s// replacement? As I
>understand it that sed is a stream editor and will try the replacement
>on every "line" it encounters. The -n flag would guarantee only the
>line changed would be printed anyway.
>

No, the address is NOT necessary for this case.  I stated that in my
reply to his post.  However, sed will only replace the first instance
found, unless the 'g' flag is specified ( s///g ).  Then it'll search
and replace globally.  The '-n' option suppresses unchanged output, so
if the output of the sed command was being redirected to a file, only
the changed lines would be printed.  So, in this case, you would NOT
want to use the '-n' option, because you would want the entire file
output *with* the changes.

>I guess what I am saying is that
> sed -n 's/^\(CLOCK=".*"\).*$/\1/p' /etc/conf.d/clock
>would do just as fine, no?
>
>W

(See above).  To actually make changes to the file, once you had
tested your regular expressions to STDOUT, you would most likely want
to redirect it to a file to replace the original file.  If you include
the '-n' option, all of the unchanged lines would not be printed or
redirected - so you would have your changes, but nothing else.

So for your final "run", you would want something without the '-n'
option.  And without the '-n' option, the print command ( s///p ) is
moot.  (See my most recent reply to the OP for a final solution.)

- --
gentux
echo "hfouvyAdpy/ofu" | perl -pe 's/(.)/chr(ord($1)-1)/ge'

gentux's gpg fingerprint ==> 34CE 2E97 40C7 EF6E EC40  9795 2D81 924A
6996 0993
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDbwOjLYGSSmmWCZMRAmG9AJ46OE4xLI3pCKnb3RTQSCIGWNKSBgCfWOOl
V9zFRF6QNqmVSK0LHjt4e9c=
=tnMC
-----END PGP SIGNATURE-----

-- 
[email protected] mailing list

Reply via email to