To remove new line character

Hi,
I am facing one interesting problem :
I have a file which contains data like this
459,|1998-11-047|a |b |c \n efg | d|e | \n
459,|1998-11-047|a \n c|b |c \n efg | d|e | \n
Basically what I have to do is , I have to remove all \n which is coming ( enclosed ) in between two pipes ( | ).. The red coloured only...
The problem I am facing is , when i try to do it using sed .. because of this \n , sed takes the entries after it as next record.

Could you please help me

Shihab

sed -e 's#|\([^|][^|]*\)\\n\([^|][^|]*\)|#|\1\2|#g' file

Thanks for your help vgersh99

But it is not working
I will explain my problem with an example

Here is the input file
$cat input.dat
|a|b
c|d|
|e|f|i|
|h|i|j|

and out put should be like this
$cat output.dat
|a|bc|d|
|e|f|i|
|h|i|j|

Here the first two lines have been joined since new line is not in between |

Thanks in advance
Shihab

perl -e 'while (<>) { if (! /\|$/ ) { chomp; } print ;}' input.dat > output.dat

should work assuming the correct end of line is always preceeded with a '|' character.

If you have trailing spaces or suchlike on the lines then it needs a little modification.

1 Like
tr -d '\n\' < file.dat

where file.dat

AFD|asdf|
asdf|ADF|
ASD|ASDF|ASDF|ASDFA|

and the output of the command is

AFD|asdf|asdf|ADF|ASD|ASDF|ASDF|ASDFA|
# cat file.txt
|a|b
c|d|
|e|f|i|
|h|i|j|


sed 'N; s/\n[       ]*\([^|]\)/\1/g' file.txt
|a|bc|d|
|e|f|i|
|h|i|j|

Thanks a loooooot!!!!!
My problem have been solved....

The Solution Suggested by Unbeliever is working fine....
When I tried with the solution by jerardfjay , it gives me the following error : Segmentation fault(coredump) .. Could you please tell me why ? I am using AIX 5.

The solution with sed by reborg is also working fine.. but it fails , if more that one \n is there in a single line. It appends the first with second..and so on... any way could you please explain the code.. if you don't mind

Thanks once again
Shihab

Hi,

I am facing the same problem as shihabvk just that my row does not end with any particular character and my delimiter of the file is #~# as this in one combination of unique character in the file that does not matches the column data.

For eg.
asds #~#sdsdf#~#fsadf#~#sfad \n sdf \n sdsf \#asdnf \n
sdfdf#~#sadfs#~#sfwe#~#sdfsdf \n sdf s sdf \n#~# \n

and i want it in this format

asds#~#sdsdf#~#fsadf#~#sfad sdsf \#asdnf \n
sdfdf#~#sadfs#~#sfwe#~#sdfsdf sdf s sdf \n#~# \n

This requirement is only for the 4th column. Please help in out with this.

Thanks in advance.
gemi