in reply to Re: make a search pattern and remove duplicate from the file
in thread make a search pattern and remove duplicate from the file
I think what he is asking for is to print out only the first instance of any line which has a unique value of the pet, hate tuple.
Any other lines should be ignored.
Since the structure you are building does not keep track of which line came first, looping over it will never bring you to the answer he is looking for.
If you really wanted to do this with a one liner, (and I'm definitely not saying you should), I would do this, which will print exactly the result he asked for:
perl -wlF'\|' -e 'for (@F) { /(\w+)="(\w+)"/; $r{$1} = $2 } $x="$r{pet}:$r{hate}"; $s{$x} ? next : ++$s{$x} && print' <input pet="cat"|hate="rat"|like="dog" pet="cow"|hate="rat"|like="dog"
Best,
Jim
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: make a search pattern and remove duplicate from the file
by NetWallah (Canon) on May 11, 2018 at 20:15 UTC | |
by jimpudar (Pilgrim) on May 12, 2018 at 15:30 UTC |