1

I have .csv file in Notepad++ that contains data like this:

1-6-2018,"(101)","","Sale",-862.96,,
"(Sale)",,837.96,
,"Diesel",12.000 Ltr,69.83/Ltr,837.96,
"Sales @ 5%",,23.80,
,"Polishing Cloth",1 Pcs,23.80/Pcs,23.80,
"CGST @ 2.5%",,0.60,
"SGST @ 2.5%",,0.60,
"(No. :16532)",
1-6-2018,"(149)","","Sale",-3212.18,,
"Sales(Sale)",,3212.18,
,"Diesel",46.000 Ltr,69.83/Ltr,3212.18,
"(No. :16533)",
// and many more

How can I use search and replace (or any other method) in Notepad++ to merge all lines that do not begin with a date, so the end result look like this?

1-6-2018,"(101)","","Sale",-862.96,,"(Sale)",,837.96,,"Diesel",12.000 Ltr,69.83/Ltr,837.96,"Sales @ 5%",,23.80,,"Polishing Cloth",1 Pcs,23.80/Pcs,23.80,"CGST @ 2.5%",,0.60,"SGST @ 2.5%",,0.60,"(No. :16532)",
1-6-2018,"(149)","","Sale",-3212.18,,"(Sale)",,3212.18,,"Diesel",46.000 Ltr,69.83/Ltr,3212.18,"(No. :16533)",

Each line that does not begin with a date is merged with the previous one...

5
  • Ctrl+H
  • Find what: \R(?!\d{1,2}-\d{1,2}-\d{4})
  • Replace with: LEAVE EMPTY
  • check Wrap around
  • check Regular expression
  • Replace all

Explanation:

\R          : any kind of linebreak
(?!         : start negative look ahead, make sure we don't have after:
  \d{1,2}   : 1 or 2 digits
  -         : a dash
  \d{1,2}   : 1 or 2 digits
  -         : a dash
  \d{4}     : 4 digits
)           : end lookahead (ie. a date)

Result for given example:

1-6-2018,"(101)","","Sale",-862.96,,"(Sale)",,837.96,,"Diesel",12.000 Ltr,69.83/Ltr,837.96,"Sales @ 5%",,23.80,,"Polishing Cloth",1 Pcs,23.80/Pcs,23.80,"CGST @ 2.5%",,0.60,"SGST @ 2.5%",,0.60,"(No. :16532)",
1-6-2018,"(149)","","Sale",-3212.18,,"Sales(Sale)",,3212.18,,"Diesel",46.000 Ltr,69.83/Ltr,3212.18,"(No. :16533)",

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.