\n removal between two |

I have a multi-line string I'm trying to do some clean-up on.

Example:

1|575|67866|"fgnhdgj"|"afhgajh
agfajgf
ahfjhgfk
ahfkhf"|568

2|56|5435|"mayank"|"gupta
gdja
agdjagf"|677

3|5666|5435|"mayank"|"gupta
gdja
agdjagf"|677

I need a shell script that replace all \n under " ".

Here's how it should look after replacement:

1|575|67866|"fgnhdgj"|"afhgajh agfajgf ahfjhgfk ahfkhf"|568
2|56|5435|"mayank"|"gupta gdja agdjagf"|677 
3|5666|5435|"mayank"|"gupta gdja agdjagf"|677

Thanks
Mayank

awk '{ORS=(NF)?FS:RS}1' file
awk '/./{printf $0 FS;next}1' OFS=\| infile

Hello Danmero,

please see attached file dumy.txt .
Ideally it must contain only one line but as all columns are | separated .
but data is coming in multi line

Please help me out

Thanks
Mayank

@danmero

You should replace X with " "

I already replaced by FS , however if you check the sample file look like I was correct from the beginning and X is the solution.

I'll have to find another solution :wink:

Try:

perl -F"\n\n" -0ane 'print map {s/\n/ /g;($_ . "\n")} @F' file

Look like your record-set is not complete , I think tr will fix your multiline problem.

tr -d \\n < file

@danmero
Yup, ... the double cross-posts made my remark obsolete...

I am still not able to convert the file.
Let me explain with example:

I am having one table in oracle with data type CLOB, and it contains data like :

See Attached as Table

Now when I am trying to export this in a text file with pipe separated using TOAD/SQL developer
Then it comes like:

Mayank|1|Fhfdsjhf
gadfjh
hdkhgkdg

Rahul|2|Fgjshagfuagf
gfjsadhgfjusa
ahfdagf
afjhgfjgahk
Bafj

Abhishek|3|Jgfsjakgf
fgusgushau
gabfjhkj

And when I am trying to insert this data in another table with Varchar column instead of CLOB, the table used to consider 2nd line of each record as New record ant try to load in 1st column, so it rejects the data.

And what I want is data must come like:

Mayank|1|Fhfdsjhf gadfjh hdkhgkdg
Rahul|2|Fgjshagfuagf gfjsadhgfjusa ahfdag fafjhgfjgahk Bafj
Abhishek|3|Jgfsjakgf fgusgushau gabfjhkj

--
Regards:
Mayank Gupta
Contact:0060143283396

Hi,

here's some mawk :

awk -F'|' 'BEGIN{OFS="|"; RS=""} {gsub("\n"," ",$3); print}' file
1 Like

Hi Da Peach,
I tried with the code that you have shared.
Still not able to perform what I want to do :frowning:
:confused:

As this code use to replace only 1st record not all the records