How to add "" quotes or [] to each line

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

How to add "" quotes or [] to each line

Postby kruto » Sat Jan 29, 2005 6:58 am

For example:

word1
word2 word3
word4
word 5

become:

"word1"
"word2 word3"
"word4"
"word 5"

or

[word1]
[word2 word3]
[word4]
[word 5]



Thanks !
User avatar
kruto
Newbie
 
Posts: 2
Joined: Sat Jan 29, 2005 12:00 am

Re: How to add "" quotes or [] to each line

Postby mrainey56 » Sat Jan 29, 2005 9:42 am

Do a search and replace with the regular expression option checked. Unix mode active (see Advanced > Configuration > Find Tab to set)

Search: ^(.+)$
Replace: "\1"

or

Replace: [\1]
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina

Re: How to add "" quotes or [] to each line

Postby kruto » Sun Jan 30, 2005 5:54 am

Thank you, works fine :)
User avatar
kruto
Newbie
 
Posts: 2
Joined: Sat Jan 29, 2005 12:00 am

Re: How to add "" quotes or [] to each line

Postby lizard » Fri Feb 25, 2005 6:26 am

Great - glad someone has asked. I use UE for MapBasic, which doesn't have a block comment function.

I tried your solution
(Regular expressions / unix style enabled replace ^(.+)$ with '\1')

on the following text:

open file logfileP for append as #2 filetype "TEXT"
write #1, "[1997 completed]"
write #2, "[1997 completed]"
close file #2

But got: "Search string not found."

I actually need single quotes, but was just testing the principle.

What am I doing wrong, please?

Thanks, 8O Bruce

I am using version 7.10b, which doesn't have the EDIT - ADD COMMENT function.
User avatar
lizard
Newbie
 
Posts: 1
Joined: Fri Feb 25, 2005 12:00 am

Re: How to add "" quotes or [] to each line

Postby ASTTMan » Tue Mar 01, 2005 12:12 pm

You might need to check Replace All is from Top of File in the Replace dialog. I got the same result when I unchecked it.

Dave
User avatar
ASTTMan
Basic User
Basic User
 
Posts: 26
Joined: Fri Feb 18, 2005 12:00 am
Location: Arlington, TX

Re: How to add "" quotes or [] to each line

Postby psmithphil » Wed Mar 16, 2005 8:02 pm

Thank you for this post, mrainey56! With it I was able to add a semi-colon at the end of each line in a large file. You da man!
User avatar
psmithphil
Newbie
 
Posts: 5
Joined: Wed Mar 16, 2005 12:00 am
Location: Kansas, USA

Re: How to add "" quotes or [] to each line

Postby Yendor04 » Thu May 11, 2006 3:55 pm

Hey lizard,

I was having the exact same issue you describe above. I found that by selecting the "UltraEdit style Regular Expressions" option (not the "Unix style") under Advanced -> Configuration -> Search -> Regular Expression Engine I was able to use then the Find/Replace strings specified earlier in this thread.

I would like to know how to use the Unix Style expression for this sort of inserting of text.
User avatar
Yendor04
Newbie
 
Posts: 6
Joined: Wed Feb 08, 2006 12:00 am

Re: How to add "" quotes or [] to each line

Postby deeptinker » Thu May 11, 2006 8:43 pm

Whole books have been written about regular expressions. (Try O'reilly Books.) It will take a while before you get comfortable with them.

Note that the latest versions of UE/UES have Perl style regular expressions. They build on the Unix style, but take things to a whole new level of difficulty. :)

Travis
User avatar
deeptinker
Basic User
Basic User
 
Posts: 14
Joined: Fri May 06, 2005 11:00 pm

Re: How to add "" quotes or [] to each line

Postby Yendor04 » Thu May 18, 2006 12:45 pm

Absolutely, deepthinker! Immediately following my post above I placed and order for "Mastering Regular Expressions, Second Edition" by Jeffrey Friedl and from O'reilly Publishing. Can't wait to crack that cover! Thanks!
User avatar
Yendor04
Newbie
 
Posts: 6
Joined: Wed Feb 08, 2006 12:00 am


Return to Find/Replace/Regular Expressions