Page 1 of 1
Replacing a column value in textpad
Posted: Mon Jul 11, 2011 3:26 pm
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
Posted: Mon Jul 11, 2011 4:34 pm
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
Posted: Mon Jul 11, 2011 4:39 pm
by manikambh
Thanks a lot It worked very well.
Can you explain why 48 is searched.
Posted: Mon Jul 11, 2011 7:03 pm
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"
Got It
Posted: Tue Jul 12, 2011 10:49 am
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.
Posted: Tue Jul 12, 2011 11:18 am
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.
Posted: Tue Jul 12, 2011 11:58 am
by manikambh
Thanks Ben for the advice..
Ill keep in mind..Thanks once again.