[Klug-general] sed - How to delete all but first occurrence?

David Halliday david.halliday at gmail.com
Thu Jan 19 12:56:52 UTC 2012


Hi, thanks for the reply, this would be fine if I didn't have to extract
the error rows into another location and then concatenate them back in.
While that isn't too difficult (grep them out, sort, unique then cat them
back in). As far as solutions go I'd rather just keep the script
simpler/cleaner and delete all instances.

This is what I want to achieve.

Input File:
====================================================================
some information: blable
This was happening: blah blah

error: something went wrong
error: I'm not happy
error: something went wrong
error: something went wrong
error: something went wrong
error: something went wrong
error: I'm not happy
error: I'm not happy

Summary
Stuff that worked: 10,000
Errors: 8
====================================================================


Output:
====================================================================
some information: blable
This was happening: blah blah

error: something went wrong

Summary
Stuff that worked: 10,000
Errors: 8
====================================================================

Or
====================================================================
some information: blable
This was happening: blah blah

error: something went wrong
error: I'm not happy

Summary
Stuff that worked: 10,000
Errors: 8
====================================================================


I'll play with awk a bit. See if that gets me where I want to be.


On 19 January 2012 12:37, Paul Littlefield <info at paully.co.uk> wrote:

> On 19/01/12 10:47, David Halliday wrote:
>
>> More Ideal would be to include only one instance of the unique error
>> messages but I believe that will be a little more complicated and more time
>> than it is worth (not to mention that a more complicated solution is harder
>> to explain to people I'm working with).
>>
>
> cat /tmp/error.txt |grep '^error' |sort |uniq
>
> Paully
>
>
> ______________________________**_________________
> Kent mailing list
> Kent at mailman.lug.org.uk
> https://mailman.lug.org.uk/**mailman/listinfo/kent<https://mailman.lug.org.uk/mailman/listinfo/kent>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/kent/attachments/20120119/6f5bc7ce/attachment-0001.htm>


More information about the Kent mailing list