I was trying to remove some duplicate string in a line by line text. eg:
A {id: "x" p {id: "vcv" v: "i4"} on:taf"}
A {id: "y" p {id: "wse" v: "i4"} on:ue"}
A {id: "z" p {id: "das" v: "i4"} on:tade"}
A {id: "x" p {id: "da" v: "i4"} on:faer"}
A {id: "y" p {id: "werw" v: "i4"} on:asee"}
A {id: "y" p {id: "werw" v: "i4"} on:asee"}
the output should be the ones with no duplicated A_id, which means the output should be:
A {id: "x" p {id: "vcv" v: "i4"} on:taf"}
A {id: "y" p {id: "wse" v: "i4"} on:ue"}
A {id: "z" p {id: "das" v: "i4"} on:tade"}
The problem I met was I don't know how to sort and make it unique with a substring only. I tried to use:
cat input.txt | grep 'A\s\{id:\s\"[^;]*\sp\s\{id:' | sort -u > output.txt
But it doesn't remove the duplicate substring but only remove lines which are exactly the same with others. So it's like it only removed:
A {id: "y" p {id: "werw" v: "i4"} on:asee"}
which is all the same with the last two lines, but didn't remove:
A {id: "y" p {id: "wse" v: "i4"} on:ue"}
which has the duplicate id but different content.