in reply to make a search pattern and remove duplicate from the file
You should use HTML tags to format your post. It's very difficult to tell what you are asking the way you posted it!
I'm assuming you meant this:
Hi , I have a file which have input as like below pet="cat"|hate="rat"|like="dog" hate="rat"|like="dog"|pet="cat" hate="rat"|like="horse"|pet="cat" pet="cow"|hate="rat"|like="dog" hate="rat"|like="dog"|pet="cow" And output im looking is pet="cat"|hate="rat"|like="dog" pet="cow"|hate="rat"|like="dog" Any first instance where I find unique value for pet and hate I wanted + to print. Thanks
You should have tried your hand at writing a solution and posted the code, but since I'm feeling generous here is a solution which you can pipe your input file to:
#! /usr/bin/env perl use strict; use warnings; my %pet_hate; while (<>) { my ($pet) = /pet="(\w+)"/ or next; my ($hate) = /hate="(\w+)"/ or next; my ($like) = /like="(\w+)"/ or next; $pet_hate{"$pet:$hate"} //= { pet => $pet, hate => $hate, like => $like, }; } foreach (values %pet_hate) { printf(qq{pet="%s"|hate="%s"|like="%s"\n}, $_->{pet}, $_->{hate}, $_->{like}); }
Best,
Jim
|
|---|