1
I want to delete both lines of a duplicate pair in a text file.
There is no way to do this using sort -u file or awk '!a[$0]++' file which both delete duplicated lines.
Somehow I would have to capture the deleted lines and run sed to use this list and then delete the already deleted (is there some way to get this output?). The pattern of the duplicated lines is not predictable.
I am looking for a shorter way than writing a complete bash program. It seems like a useful tool and there should be an easy way to do it.
Easy to delete one of the duplicates. I need to delete both and can't find a way to do it. Encountered during parsing.
1
Please note that https://superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?.
– DavidPostill – 2019-12-09T21:41:19.767Is it necessary to maintain the order of the lines? – dirdi – 2019-12-09T21:42:03.833
Yes I need to maintain order – user322035 – 2019-12-09T21:48:29.990
How large is the file; does it fit in memory? – user1686 – 2019-12-09T21:58:50.077
Not a large file. 10-200 lines of ascii text – user322035 – 2019-12-09T21:59:36.210
I voted to reopen. If the file is not very large then something like
awk '{a[$0]++; 1} END {for (line in a) if (a[line] == 1) print line}'may be a good start. – Kamil Maciorowski – 2019-12-10T10:03:45.760Thanks... redid script so I don't need to do this! Found a better way. – user322035 – 2019-12-10T15:04:10.450