How to put all lines starting with a specific character combination on the previous line in Excel or Notepad++?
I'm trying to import the following CSV data set into Excel. I'm using the Text Import Wizard to set the right delimiters. So far, I used the ";" and "," delimiters.
Here is the result so far. The data set seems to be looking fine, until row 493. From that point on, the data changes from the year 2014 to 2015. Somehow, the format of the data seems to have changed somewhat from that point on, resulting in a CSV file in which the columns are not aligned anymore.
Here's a snapshot of what happens in Notepad++:
I've already asked about this problem over here, but so far that question has not yielded a solution. I've also considered taking up the advice in this Super User question, but I think I can't apply it in this situation because the character combination to use is “",”, and Notepad++ does not seem to recognize \R(?="";")
in the document.
I'm now considering to solve this problem by putting lines starting with the “",” character combination on the previous line.
Question: what should I do to format this CSV data set in such a way that all rows starting with “",” are put on their respective previous lines? (Either in Notepad++ or Excel.)
It seems to me this is a data cleaning task for the original file from the download link above. My answer is based on this file! This is not identical with the screenshot shown in your question here.
In addition to the different format from line 493 on, there are also some special characters like long hyphens and some more problems. Please note that there are also control characters (tabs) in the data set, which should be removed.
Please note, the CSV file is not a Windows file format:
-
\n
= LF (Line Feed) → Used as a new line character in Unix/Mac OS X -
\r\n
= CR + LF → Used as a new line character in Windows
Please make shure to copy your file before starting and try this quick and dirty solution with some manual work using Notepad++.
(1) set a special character for later use:
- Ctrl+H
- Find what:
\"\n
- Replace with:
\"#\n
- CHECK Wrap around
- CHECK Regular expression
- Replace all
(2) replace all LF
- Find what:
\n
- Replace with:
LEAVE EMPTY
- CHECK Wrap around
- CHECK Regular expression
- Replace all
(3) Reset clean Line Feeds
- Find what:
\"#
- Replace with:
\"\n
- CHECK Wrap around
- CHECK Regular expression
- Replace all
(4) Search for lines Find what ^","
and edit manually less than 20 lines by deleting the line feed.
BTW - I noticed the records are georeferenced. Excel is probably not very suitable for this (see QGIS screenshot below).