Join lines

Find, replace, find in files, replace in files, regular expressions

Join lines

Postby ganda » Wed Nov 29, 2006 1:38 pm

I can't find out how to join lines. :)

There's no such option in UE?
User avatar
ganda
Basic User
Basic User
 
Posts: 11
Joined: Wed Mar 23, 2005 12:00 am

Re: Join lines

Postby Bego » Wed Nov 29, 2006 2:04 pm

What do you want to do ? Just for 2 lines?
Go to the end of line 1 and press the "del" key.
Line 2 jumps up then.

Otherwise, explain more ....
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Join lines

Postby ganda » Wed Nov 29, 2006 3:01 pm

I want to join more lines to one line, many times in my text.

I cannot find any JOIN LINES option in UE.

BTW, i know the del key :)
User avatar
ganda
Basic User
Basic User
 
Posts: 11
Joined: Wed Mar 23, 2005 12:00 am

Re: Join lines

Postby Bego » Wed Nov 29, 2006 3:35 pm

Ah yes, ok. Mark the lines you want to join and let run this macro:
(I call this joinLines):

Code: Select all
InsertMode
ColumnModeOff
HexOff
PerlReOn
Find RegExp "\r\n"
Replace All SelectText ""


It runs for DOS files. For Unix files \n alone should do the job.

rds Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Join lines

Postby ganda » Wed Nov 29, 2006 3:52 pm

Thank you.

It does not work.
It joins all lines and not the selected lines :-)
User avatar
ganda
Basic User
Basic User
 
Posts: 11
Joined: Wed Mar 23, 2005 12:00 am

Re: Join lines

Postby Bego » Wed Nov 29, 2006 7:33 pm

Well, it WORKED this morning in my 11.whatever version in business. I tested it there.
At home now (12.20a+4) it does not work. (I mean I read sth. similar that regexp stuff and selectedtext did not work ...)
However, if you select your lines, open your replace dialog:
find: \r\n
replace : <nothing>
range: "selected text"
and you have regexp "set on" and use the perl regexp as default (see your UE-options) it does work fine.

rds Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Join lines

Postby YanHan » Thu Nov 30, 2006 1:35 am

Try this: highlight the lines you want to be joined and select the '-> Format -> Convert CR/LFs to Wrap' from the menu.
User avatar
YanHan
Newbie
 
Posts: 5
Joined: Sun Nov 26, 2006 12:00 am

Re: Join lines

Postby ganda » Thu Nov 30, 2006 7:41 am

Yes that's it!!!!
Thank you YanHan and Bego.

I've just seen that there are too much spaces in the text.

p.e.

this is the
text to
join

--->

this is the (2 spaces) text to (2 spaces) join

(?)
User avatar
ganda
Basic User
Basic User
 
Posts: 11
Joined: Wed Mar 23, 2005 12:00 am

Re: Join lines

Postby Mofi » Thu Nov 30, 2006 8:33 am

Hi to all here!

Why are you all making things more complicated as needed?

Removing the line terminations from all lines of a selection can be done with an extremly simple non regular expression replace in selected area.

  1. Select the area.
  2. Press Ctrl+R to open the replace dialog
  3. Enter ^p in the Find What field and make sure nothing is in the Replace With field.
  4. Uncheck any additional option.
  5. Select Selected Text in the Replace Where group.
  6. Press button Replace All.
That's it for files with DOS line terminations or UNIX/MAC files open with temporary conversion to DOS format as I always suggest.

For UNIX files opened really in UNIX mode use ^n instead of ^p.

The procedure above as macro if you often need it:

IfSel
Find "^p"
Replace All SelectText ""
EndIf

Well, this macro will not work with UltraEdit v12.10b or UEStudio v6.00a if the Perl compatible regular expression engine is active although the replace is not a regular expression. Upgrade or downgrade to any other version of UE/UES which don't have this strange bug or don't use the Perl engine.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4054
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Join lines

Postby ganda » Thu Nov 30, 2006 8:52 am

Thank you Mofi.
That is the solution!

If I select all text the whole text will be joined to 1 line.

Would it be possible if double LF/CR not to replace the second LF/CR?
User avatar
ganda
Basic User
Basic User
 
Posts: 11
Joined: Wed Mar 23, 2005 12:00 am

Re: Join lines

Postby Mofi » Thu Nov 30, 2006 9:16 am

ganda wrote:Would it be possible if double LF/CR not to replace the second LF/CR?

No and yes!

No because DOS files have CR/LF and not LF/CR.

Yes, but now you need a regular expression search and replace.

IfSel
UnixReOff
Find RegExp "^p^([~^p]^)"
Replace All SelectText "^1"
EndIf

Add UnixReOn or PerlReOn (v12+ of UE) before command EndIf if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style.

The regular expression now removes the CRLF only if a following character exists which is not a CRLF line termination.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4054
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Join lines

Postby Bego » Thu Nov 30, 2006 9:31 am

Mofi war mal wieder schneller :-)

I did the perl regexp approach, but it does it similar.
I just say a "word character" instead of a "non paragraph"
A ^p seems not to work in this case:

Find: (\w)\r\n
rep: <nothing>

Code: Select all
111
222

empty line before
444
555

Code: Select all
111222
empty line before444555
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Join lines

Postby ganda » Thu Nov 30, 2006 9:52 am

Mofi wrote:IfSel
UnixReOff
Find RegExp "^p^([~^p]^)"
Replace All SelectText "^1"
EndIf

Thank you Mofi.
It still creates one line of text. :(
User avatar
ganda
Basic User
Basic User
 
Posts: 11
Joined: Wed Mar 23, 2005 12:00 am

Re: Join lines

Postby Mofi » Thu Nov 30, 2006 10:27 am

Then in your file there is no CRLF CRLF, there are CRLF 1 or more spaces or tabs CRLF. So please tell us at last what your file really contains exactly and how it should look like after the replace/macro.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4054
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Find/Replace/Regular Expressions