tags:

views:

222

answers:

2

I have several thousand lines of delimited data. Unfortunately some of my data wrapped to a new line. How can I search for all lines that do not contain my delimeter then join with the prior line, skip to the next line then continue until the end of the buffer?

Buffer before

1243|This is all one
line
1235|This fits on one line.
43223|This line wraps
for some reason.

Buffer after

1243|This is all one line
1235|This fits on one line.
43223|This line wraps for some reason.

+5  A: 

This is a good job for keyboard macros. Try something like this:

C-x (
M-x isearch-forward-regexp RET
^[^|]*$ RET
M-^
C-x )

where
  C-x (                            begins recording a keyboard macro, which consists of
  M-x isearch-forward-regexp RET   searching forward using a regular expression
  ^[^|]*$                          representing a line containing no | characters, then
  M-^                              joining the current line to the previous line and
  C-x )                            ending the keyboard macro definition.

This macro can be invoked manually multiple times with C-x e (kmacro-end-and-call-macro), or you could save it as a function and call it programmatically as described at http://www.emacswiki.org/emacs/KeyboardMacrosTricks.

jlf
Invoke it with `C-u 10000 C-x e` for maximum fun!
seth
Or `C-u 0 C-x e` which will run until it gets an error.
Ivan Andrus
+3  A: 

Try M-x query-replace-regexp, search for

^\(.\+|.\+\)\n\([^|]\+\)$

And the replacement:

\1\2

HTH

Zsolt Botykai