[Klug-general] sed - How to delete all but first occurrence?
Roger Gammans
rgammans at gammascience.co.uk
Thu Jan 19 13:21:00 UTC 2012
On Thu, Jan 19, 2012 at 12:56:45PM +0000, David Halliday wrote:
> 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.
if you've got Perl, try:-
perl -ne 'BEGIN:{my %err;} if (/error/) { if (not $err{$_}) { $err{$_} =1 ; print;} } else {print;}'
It should be possible with sed too.
TTFN
--
Roger. Home| http://www.sandman.uklinux.net/
New key Fpr: 0F2F E1DF 4CD2 5E7B EF9F B173 4CFA F143 ADBE 6B00
More information about the Kent
mailing list