notepad++ remove new line in " " at my csv-file - csv

My problem is that I have a csv-file with alot of new line. How can I remove the newlines with select and replace? My other stuff should stay how it is.
Here the example:
101080;101080;101080;104;
101098;101098;101098;105;
101099;101099;101099;106;"RING 750GG 1BRI TW VS 0,0300ct 1 RUBIN WEITE58.0
BREITE 4.5mm
72-91872-0-0 045-71-0-58-3
704.- VP1000.-
";
1011;1011;1011;106;
101093;101093;101093;123;
I have all over the csv file these new lines. I need to make that in 1 line.
thank you for the help

If I understand the question correctly, you only wish to remove the newlines for any lines that do not end in a semicolon character. You can do that below with this Find and Replace in Notepad ++ using the Regular Expression Search Mode.
Find: ([^;]$)(\r\n)
Replace: \1
Explanation of the find is that it is looking for the end of line and newline character that isn't preceded by a semicolon character. The parenthesis tell the find to group the results, which allows us in the replace to just keep the first grouping of find results and to discard the newline characters for these lines that don't end in a semicolon, which will then end up making it all line up on the previous line.

Here is a simple solution:
Activate the ShowAll Icon (¶) in the toolbar of Notepad++
Mark a ; and NewLine-Sequence (CR LF) in your file
Use the shortcut Ctrl + F
Select the Replace tab in the appeared search window
Insert ; in the Replace with text box
Press Replace All
Now all items ending with a ; are in single rows.

To remove all new lines: Just replace "\r\n" (windows) or "\n" (unix) with nothing! Using Extended or Regex options.
To just remove some:
First add unique data where you want to keep the new line - I use "QAZ".
Then remove all new lines as above.
Then replace "QAZ" with "\n".

Related

Change string to only one line i csv

I have csv file where each record is one line. Problem is that sometimes one cell have few lines. For example:
first;second;third;something something something something;four
first;second;third;something
something
something something;four
I opened this in Notepad++ and i see that end of record has LF white tag and new lines in cell has CR white tag.
How can I remove this CR white tags? I would like to have after convert:
first;second;third;something something something something;four
first;second;third;something something something something;four
Answer 1: Provided you can uniquely identify where you want to remove the newline
Find: “(Pattern 1 at end of line)\r\n” - Replace with “\1”
Or Find: “(Pattern 1 at end of line)\r\n(Pattern 2 at start of next line)\” - Replace with “\1\2”
Answer 2: Instead if you can identify where you want to keep the newlines
Find: “(Pattern 1 at end of line)” – Replace with “\1QAZ” where “QAZ” is not anywhere in the file. Continue until "QAZ" is everywhere you require
Remove all new lines by Find “\r\n” – Replace with nothing.
Restore required new lines by Find “QAZ” – replace with “\n” – windows Notepad++ does not need the \r

Notepad++ tabs to spaces everywhere other than beginning of line

Due to a new coding style that I've been having to use I'm required to use tabs in the beginning of lines but spaces everywhere else to align things.
Is there a way to customize notepad++ to only replace tabs with spaces if it's not at the beginning of a new line?
Just as an example of what I mean I'll use this bit of 'code':
function someFunction():
while(true):
veryLongCodeStuff() // Some comment
shortCode() // Aligned comment
Which I would have to write like this (where \t = tab and a "." represents a space):
function someFunction():
\twhile(true):
\t\tveryLongCodeStuff()..// Some comment
\t\tshortCode()..........// Aligned comment
To convert existing files, I would suggest a two step approach:
replace all tabs with spaces (this can be done with Edit -> Blank operations -> TAB to Space )
replace spaces at the beginning of lines: do a regular expression find/replace like this:
Open Replace Dialog
Find What: ^([\t]?)( ){4} instead of 4 use the number of spaces you have configured as tab width
Replace With: \1\t
check regular expression
click Replace All: as each Replace All replaces only one indent level for all lines: repeat until the status bar of the find dialog tells you, that no more replacements were done (just keep Alt-A pressed for a second or two)

Sublime Text regex to find and replace whitespace between two xml or html tags?

I'm using Sublime Text and I need to come up with a regex that will find the whitespaces between a certain opening and closing tag and replace them with commas.
Example: Replace white space in
<tags>This is an example</tags>
so it becomes
<tags>This,is,an,example</tags>
Thanks!
You have just to use a simple regex like:
\s+
And replace it with with a comma.
Working demo
This will find instances of
<tags>...</tags>
with whitespace between the tags
(<tags>\S+)\W(.+</tags>)
This will replace the first whitespace with a comma
\1,\2
Open Find and Replace [OS X Cmd+Opt+F :: Windows Ctrl+H]
Use the two values above to find and replace and use the 'Replace All' option. Repeat until all the whitespaces are converted to commas.
The best answer is probably a quick script but this will get you there fairly fast without needing to do any coding.
You can replace any one or more whitespace chunks in between two tags using a single regular expression:
(?s)(?:\G(?!\A)|<tags>(?=.*?</tags>))(?:(?!</?tags>).)*?\K\s+
See the regex demo. Details
(?s) - a DOTALL inline modifier, makes . match line breaks
(?:\G(?!\A)|<tags>(?=.*?</tags>)) - either the end of the previous successful match (\G(?!\A)) or (|) <tags> substring that is immediately followed with any zero or more chars, as few as possible and then </tags> (see (?=.*?</tags>))
(?:(?!</?tags>).)*? - any char that does not start a <tags> or </tags> substrings, zero or more occurrences but as few as possible
\K - match reset operator
\s+ - one or more whitespaces (NOTE: use \s if each whitespace must be replaced).
SublimeText settings:

Insert same code around different filenames

I am making a small online database that is accessible through the form of checkboxes for download. I was wondering if there was some way to list all of the filenames available for download in Sublime Text 2 and insert the same code around each filename?
Everything is functional, it would just save me a lot of repetitive copy and pasting if there is a faster way to do this.
Use SublimeText Find & Replace. Click the Regex button (it looks like a * to the left of the search box)
In the Find box, insert: (^.*$)
In the replace box: [yourcode]$1[yourcode]
Where [yourcode] is what you want to insert into the box.
So, if you want to make them all <li> then your replace box would be:
<li>$1</li>
Remember to use escape \ characters where they are needed, in case you need to insert restricted characters.
^ - beginning of a new line.
. - wildcard
* - any number of the previous character in the sequence (in this case a wildcard, so any text)
$ - the end of a line
() - denotes a block, it's how the $1 knows what text to put in it's place.
Sublime Text Search and Replace
Use search/replace on a text editor with regular expressions.
^ and $ represent the beginning and end of a line - thus allowing you to easily surround each line with the appropriate text.
Sometimes you can copy the newline character (as in copy the end of one line to the beginning of the next line), and replace that with whatever text you need.
You could always use the regular expression search / replace feature in Notepad++.

Merge multiple lines into one using Sublime Text

I am very new to Sublime Text and I am sure this is a naive question. Watching the Multiple line selection at http://www.sublimetext.com/ (2/6 slide). Absolutely love it.
I understand that Ctrl (Cmd)+Shift+L "multiple-selects" so that we could do the edit simultaneously. However, in the demo, they also merge all the lines into 1 single line. What is the shortcut for that?
I used Ctrl+J but it just deletes once and not all the occurrences of new line.
I use TextPad and use Find/Replace \n with an empty space. But it seems that the person giving the demo uses some kind of shortcut.
A single command shortcut for merging multiple lines into 1 is "join lines".
Command + Shift + J on the Mac to join lines.
CTRL + Shift + J on Windows
Edit > Lines > Join Lines
Important note: This keyboard shortcut changed in versions of sublime text released after around mid-2021. For older versions, use Command + J, or CTRL + J.
Another approach is seen in the demo animations on sublimetext.com. Using multiple selections, Ctrl+Shift+L is used to split a selection into lines, and each line is then edited simultaneously. end + del will then remove all line breaks. This can be seen in slide 2/6 at http://sublimetexttips.com/7-handy-text-manipulation-tricks-sublime-text-2/
I think that, in the demo, he presses Del, with the cursor at the end of the line, in multiple selection. This way the \n is removed in every selected line.
ctrl+a and ctrl+j seems working on sublime text 3.
Editing
join Joins the following line to the current line, replacing all in between whitespace with a single space
http://www.sublimetext.com/docs/commands
Go to edit option in menu, Edit -> line -> join lines
Select the lines you want to merge and press Ctrl + j and if you want to make all file in 1 line then do Ctrl + a and Ctrl + j.
If you want to merge lines into one line that will also remove the starting, and ending space from the line, the following regex should work:
Find What: ^\s*(.+)\s*\n
Replace With: \1
Sublime Text 3 for Mac:
cmd + j no longer works and is now CMD + SHIFT + J
Join lines is a good command, but it adds spaces between the merged lines. To merge lines without spacing, the easiest way appears to be the following:
Find -> Replace (Command+Option+F on Mac)
Ctrl+Enter to enter newline to the Find What field.
Don't enter anything into the Replace With field.
Press Replace All.
I have been using a regex approach in Sublime Text 3, as follows:
Press Ctrl+H (in Windows) to show the "Find and Replace" dialog at the bottom.
In the "Find" field, use $\n\s* (end of line, carriage return and any arbitrary number of spaces following, including zero, which should be at the beginning of the next line).
The "Replace" field should be empty.
Hit "Replace All" or Alt+Ctrl+Enter.
This should do the trick!