William L. Thomson Jr. wrote:

> Now I know some will scream, puke, throw up in their mouth, and so on.
> But seems like sed should have an OPTIONAL argument or etc to tell sed
> to either fail if it can't make the change anywhere. And/or keep/output
> a count of how many things were modified.

you could use the w flag to the s command.

 `w FILE-NAME'
      If the substitution was made, then write out the result to the
      named file.  As a GNU `sed' extension, two special values of
      FILE-NAME are supported: `/dev/stderr', which writes the result to
      the standard error, and `/dev/stdout', which writes to the standard
      output.(1)

[EMAIL PROTECTED] ~/tmp $ cat test
this is a test: 12345
line 2
line 3
line 4: 12345
[EMAIL PROTECTED] ~/tmp $ sed -i -e 's:12345:54321:w sed.log' test
[EMAIL PROTECTED] ~/tmp $ cat test
this is a test: 54321
line 2
line 3
line 4: 54321
[EMAIL PROTECTED] ~/tmp $ cat sed.log
this is a test: 54321
line 4: 54321
[EMAIL PROTECTED] ~/tmp $ sed -i -e 's:12345:54321:w sed.log' test
[EMAIL PROTECTED] ~/tmp $ cat sed.log
[EMAIL PROTECTED] ~/tmp $

or

[EMAIL PROTECTED] ~/tmp $ sed -i -e 's:12345:54321:w /dev/stdout' test | wc -l
2

-- 
                        looks like christmas at fifty-five degrees
                                    this latitude weakens my knees
    EFFD 380E 047A 4B51 D2BD  C64F 8AA8 8346 F9A4 0662 (0xF9A40662)

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to