Replacing a column value in textpad

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
manikambh
Posts: 4
Joined: Mon Jul 11, 2011 3:18 pm

Replacing a column value in textpad

Post by manikambh »

Hi Guys,

I have a file with lines starting from either 04 or 05, for lines starting with 04 I need to replace the 51 column value from N to Y.


Is it possible in Textpad?


Thanks
Manikanth
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Do you mean: for every line that begins with 04 and whose 51st character is N, you want that N changed to Y?

If so, try this:

Use "Posix" regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
Search | Replace... (<F8>):
Find what: ^(04.{48})N
Replace with: \1Y

[X] Regular expression

Replace All
manikambh
Posts: 4
Joined: Mon Jul 11, 2011 3:18 pm

Post by manikambh »

Thanks a lot It worked very well.

Can you explain why 48 is searched.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

It isn't.

^(04.{48})N matches

Code: Select all

^           the beginning of a line
(           (start of captured text number 1)
  04        the literal text "04"
  .{48}     any 48 characters (see below)
)           (end of captured text number 1)
N           the literal text "N"
where

.{48} matches

Code: Select all

.           any character (other than newline)
{48}        ... 48 times
We replace the matched text with

Code: Select all

\1          captured text number 1
Y           the literal text "Y"
manikambh
Posts: 4
Joined: Mon Jul 11, 2011 3:18 pm

Got It

Post by manikambh »

Got It thank you very much..


its been six months i am trying to learn regular expression, but everytime i get confused with the brackets or square rounded 1's and literals..its a mess...can you suggest any easy understandble material and hands on on regular expression.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

TextPad's help has some rather brief notes on regular expressions. Look under
Reference Information | Regular Expressions,
Reference Information | Replacement Expressions and
How to... | Find and Replace Text | Use Regular Expressions.

There are many regular expression tutorials on the web, and you will find recommendations for some of them if you search this forum.

A standard reference for regular expressions is

Friedl, Jeffrey E F
Mastering Regular Expressions, 3rd ed
O'Reilly, 2006
ISBN: 0-596-52812-4
http://regex.info/

But be aware that the regular expression recogniser used by TextPad is very weak compared with modern tools. So you may get frustrated if you discover a handy trick that works elsewhere but doesn't work in TextPad.
manikambh
Posts: 4
Joined: Mon Jul 11, 2011 3:18 pm

Post by manikambh »

Thanks Ben for the advice..

Ill keep in mind..Thanks once again.
Post Reply