insert text at the begining of each line

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

insert text at the begining of each line

Postby user » Mon Jun 12, 2006 5:06 pm

hello

can you tell me please, how can I insert some text at the begining and at the end of each line ?

thanks!
User avatar
user
Newbie
 
Posts: 4
Joined: Thu Jun 08, 2006 11:00 pm

Re: insert text at the begining of each line

Postby Mofi » Tue Jun 13, 2006 5:05 am

UltraEdit style regular expression:

Find What: %^(*^)$
Replace With: text at begin of line^1text at end of line

Unix/Perl style regular expression:

Find What: ^(.*)$
Replace With: text at begin of line\1text at end of line

Click on the Help button in the Find or Replace dialog and read the help article and the article "Regular Expressions" referenced at this help page.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: insert text at the begining of each line

Postby EllE » Wed Jun 14, 2006 2:18 pm

i test this :)

Code: Select all
InsertMode
ColumnModeOff
HexOff
UnixReOff
Top
Find RegExp "%^(*^)$"
Replace All "XXX^1XXX"


replaced all but only last row not :(

before:
Code: Select all
a
a
a


after:
Code: Select all
XXXaXXX
XXXaXXX
a


you must use this
Code: Select all
a
a
a



for propher
Code: Select all
XXXaXXX
XXXaXXX
XXXaXXX

User avatar
EllE
Basic User
Basic User
 
Posts: 12
Joined: Mon Jun 12, 2006 11:00 pm

Re: insert text at the begining of each line

Postby Mofi » Thu Jun 15, 2006 10:47 am

Correct. The last line of the file must be also terminated with the EOL character(s). Because I often see users which have files where the last line of the file has no line termination, I use following macro code in most of my macros at the beginning to make sure that the last line of the file is also terminated:

InsertMode
Bottom
IfColNum 1
Else
"
"
EndIf
Top

It's very simple. It moves the cursor to the end of the file. If the cursor is now at column 1, fine - nothing must be done because the last line of the file is already terminated. If the cursor at the end of the file is not at column 1, the last line is not terminated and the macro adds now the line termination according to current file format (DOS/UNIX/MAC). Next the cursor is moved back to top of the file before the real macro code starts.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Find/Replace/Regular Expressions