What I don't understand is how you define a "line". Typically, a line is terminated by '\n', so how can you have a single line "A|1|\n A" in your text file? Especially because this line will actually be "A|1|\n A\n".
To remove some of the newline characters, you could use a script (Perl or shell or whatever) that reads the file line by line, remembers the last line, then concatenates the next line to what you remember (under whichever conditions are applicable, i.e. when you consider two lines to be just one), then writes the concatenated line to a new file.