How to replace line-breaks with commas using grep in TextWrangler? - regex

I have a text-file container a number of lines, which I need to turn into a csv. What is the easiest way to replace all the line-breaks with ", ". I have TextWrangler and read that it would do so by using grep and regular expressions, but have very little experience using regular expressions and don't know how grep works. Anyone who can help me get started?

Choose Find from the Search menu. TextWrangler opens the Find window.
Select the "Grep" checkbox
Type the string you are looking for ("\n" or "\r\n" or "\r") in the Find textfield.
Type the replace string (", ") in the Replace text field.
Click "Replace All"
See chapters 7 and 8 of the TextWrangler User Manual if you have problems.

Alternatively, and with only two pieces of software (Excel and Notepad++, which is also free and AWESOME).
Take your list (I assume it's one per line, in a column, for example):
Remove any empty cells
Copy the addresses, and Paste Special>Transpose (this put them into cells going from A-->).
Copy list into notepad++ - you'll note that it shoves them in as one long list, losing that irritating table structure.
Find the shortest clear space (but use the entire space) between two email addresses, and replace all with a ","
Then find all remaining spaces (i go with one space at a time), and replace with nothing (i.e. the 'replace with' box is empty).
Et voila!
and you know you can also save stuff as comma-separated values, right?

Related

Find all semicolons surrounded by numbers in MS Office WORD

In a word document, I'd like to find all semicolons that are surrounded by numbers. so I need the Find/Replace DialogBox to find and select ; in 123;4 and 1;234 (but not example;example or not example; example) .
Please note that in the example above, I just need the semicolon selected for formatting.
I know the basics of RegEx but WORD's so called Wildcards are different. All I could do so far was to find the whole string (eg 123;4) using ([0-9]{1,};[0-9]{1,}) but like I said I only need ; so that I change it's font size, color etc.
Please help. I don't like to spend the whole day on a stupid document.
You can work around Microsoft Word's limitations by inserting a custom sequence of characters to mark the instances of ; that you want to format, and then deleting the custom sequence of characters. In this example I will use the character sequence zzzzz as this likely doesn't appear anywhere else in your document.
The Process
First do a find-and-replace:
Find what: ([0-9]{1,});([0-9]{1,})
Replace with: \1zzzzz;\2
Now you can select all instances of zzzzz; and apply the desired format.
Lastly, do another find-and-replace:
Find what: zzzzz
Replace with: nothing

How do I replace the spaces between words in Emacs?

I have a files consisting of words:
ndkjsank ndjksandknsakj
dnsjakndjskndjknsakjn dsajkndksnakjndsnajkndjkas
dsnjak a
And I would like to replace the (sometimes multiple) spaces between them with a single tab:
dsnak**\t**ndsjka
njdkas**\t**ndksjankda
njdsaibdusai**\t**nkdsnakjdnas
Is this possible using a regular expression in Emacs? I thought I might get away with using a rectangular selection area but the words are of varying length (and the file is far too long to do it manually).
EDIT:
This comes close but it also selects the spaces/newlines/tabs to the right of the second word:
\s-
The regexp you want is +. Call M-x replace-regex then replace + with \t. Note there's an empty space before the + sign.
Also, to produce the tab you might have to hit the C-qC-i keys. I'm not sure if it accepts the \t syntax when called interactively.

Multiline search replace with regexp in Eclipse

Eclipse regexp search works pretty well, so for example in search box I have this:
(?s)(myMethod.*?;)\}\);
Now I want to copy multiline text in the IDE and in replace box, for example I want to paste \1PASTE_MULTILINE_TEXT_HERE. However Eclipse does not allow me to directly copy-paste multiline text without manually inserting newline characters.
In Vim (Gvim, Macvim) it works perfectly well, keeping all the spaces; how can I do the same thing in Eclipse?
For searching multiple lines in Eclipse, you must use the 's' parameter in search expression:
(?s)someExpressionToMatchInAnyLine
For replacing with multiple lines exp you must use \R i.e:
line1\Rline2\Rline3
This will replace the matched exp with:
line1
line2
line3
Generally, the approach I've taken to doing this sort of thing is to type out what I want to use as a replacement, select that, open up the Find/Replace dialog, and copy the contents of the Find text box. I proceed from there and paste what I copied into the Replace text box. There is still a little work to be done (removing backslashes from in front of regex special characters that don't apply in the Replace box), but it gives me a hand up.

Notepad++ replace two lines with other (10) lines in open documents

I want to replace two lines with other lines in Notepad++.
The main problem is that I am not able to copy all the lines which should be replaced. Only the first line is inserted in the "Replace with:" input field if I paste all lines in the field. It seems that the line break is not correctly copied.
Selecting the lines (with the line break) which should be inserted in the "Find what:" field is quite easy because I can select them in the document and simply hit "CTRL + H".
What to do? Please no solutions how it could work with command line tools.
Regards
Albeit a bit late for an answer, I think it's OK.
You can not search for a multi line string in Notepad++ using the normal search mode.You should use the extended search mode instead.
You just have to escape the new lines.What's best, you can use Notepad++ to prepare the escaped text to be searched and replaced.
I assume you are using windows text files meaning the new line is represented with \r\n
To achieve what you want:
1.
Create a new document and paste your multiline text to be replaced
Do a replace on it using the extended search mode. Find what: \r\n Replace With:\\r\\n
The result will be your "Find what" string.
2.
Create a new document and paste your multiline replacement text
Do a replace on it using the extended search mode. Find what: \r\n Replace With:\\r\\n
The result will be your "Replace with" string.
3.
Now that you have your escaped data, do a Replace on all the open documents using the extended search mode AND the results from the previous steps.
Hope this helps.
None of these suggestions are acceptable! TextFX's Ctrl+R replace plugin falls way short.
What EVERYONE wants, everyone that wants to perform a replacement of multiline blocks of text with another multiline block of text, is this...
2 large text boxes:
Find This:
This is line one
This is LIKE two
This is line TREE
Replace with This:
This is line 1
This is line 2
This is line 3
A checkbox for "All Open Documents"
And/Or...
Option for "Find-Replace in all Files of Type"
Then a GO button............
How hard could that be to create in Notepad++? It was done way back in 1998, a freeware utility called Search-Replace 98.
UPDATE:
The plugin suggested by numediaweb DOES EXACTLY what I needed! Hats off to numediaweb for the tip and standing applause for paul at phdesign!
ToolBucket multi-line search plugin for Notepad++
http://www.phdesign.com.au/programming/toolbucket-multi-line-search-plugin-for-notepad/
ToolBucket contains the following features:
Multi-line search and replace dialog.
Change indentation dialog.
Generate GUID
Generate Lorem Ipsum
Compute MD5 Hash
Compute SHA1 Hash
Base 64 encode
Base 64 decode
Download
The latest version is available here:
https://github.com/phdesign/NppToolBucket/downloads
For regular expressions you can use Ctrl-R, aka TextFX -> TextFX Quick -> Find/Replace.
If not check this plugin, it does what you want!
Based on the response of Nikanos Polykarpou below is my...
Notepad++ - Replace by a multiple lines string
Select the string to replace (can have multiple lines).
Follow...
Ctrl+h -> Replace (tab) -> Enable "Extended (\n, \r, \t, \0, \x...)"
... in "Replace with:" enter a string to do the replace with "\r\n" (if Windows) instead of real line breaks as this example...
"model" "models/aztec100500/flo_grass.mdl"\r\n"framerate" "10"\r\n"angles" "0 30 0"\r\n"classname" "cycler_sprite"
... do the replace!

use notepad++ to format data

I have a dataset that looks like this:
1 -0.151714363660730E+03 0.681572558518519E+02
-0.147787110884357E+03 0.702453634941157E+02
-0.147765104000000E+03 0.702198060000000E+02
-0.147681722000000E+03 0.701999540000000E+02
-0.147648000000000E+03 0.702032990000000E+02
-0.147585678000000E+03 0.702033980000000E+02
-0.147505270000000E+03 0.702003840000000E+02
-0.147431532000000E+03 0.701888260000000E+02
-0.147402283000000E+03 0.701852730000000E+02
how can I use find and replace in notepad++ to put all the data on one line
The general algorithm:
Switch to advanced search mode
Replace all \r\n to space
Replace all \n to space
Switch to RegExp search mode
Replace \s+ to space
*HINTS:
depending on encoding of the endline symbol point 2 or 3 can be excluded.
I don't have English version of notepad++, and my translation of search modes could be incorrect.
Hey, and now where is the part about single space delimiter?
If you do not need it, just remove steps 4-5.
Press ctrl+h
Select 'extended'
Replace all \r\n with `` (CR+LF line endings)
Replace all \n with `` (LF line endings)
My first idea would be only a simple search and replace with this params:
from: " "
to: " "
But it's trivial, and I assume it wouldn't work, just because you asked this question. I don't know anything about your files, but there is another way to complete tasks like this using Notepad++.
You can use "Macros" very simply. You have to click to the "Recording Macros" button (Macros menu), and show a repeatable solution only for 1 line. After that you can stop the recording, and with Ctrl+Shift+P you can repeat it very quickly. It's a very useful and general solution, since i've found it I use it all the time to solve this kind of problems.