Jump to content

Removing lines from a file

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Guest_NeedHelp_*

Guest_NeedHelp_*
  • Guests
I have to remove certain lines from a file. I file may look like this:

E2EDL37005 123244544-data-data-data
E2EDL44 123123123-data-data-data
E2EDL37005 123244544-data-data-data
E2EDL44 ........

What I need to do is remove the second occurrence of E2EDL37005 if the characters beside it are the same as the first.

Also, this must be written in Linux C++ and I have no idea where to start. Can anyone point me in the right direction?

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
perhaps read the text in one line at a time, parse the line into header and data. Store them in a data structure (say a map of <string,set<string>>?) and check for duplication before writing. Obviously, for a large file this could get obnoxious.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog