Replace first character on fourth line in every file

General questions about using TextPad

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

Post Reply
tsnik
Posts: 2
Joined: Thu Sep 17, 2009 11:34 am

Replace first character on fourth line in every file

Post by tsnik »

I hope someone can help me. I have approx 1200 files and I need to change the first character in line 4 of every file to a new value. For instance, every file has a '1' in the first character of line 4, and I need to change this to a '5'. How can I do this? I am fairly new to Textpad and have not used anything more than the global Find and Replace tool so far.
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

This works in TextPad:

Search for: (.*)\n(.*)\n(.*)\n1
Replace with: \1\n\2\n\3\n5

The strings above changes from this:

Code: Select all

line 1
line 2
line 3
1 line 4
line 5
line 6
line 7
1 line 8
line 9
line 10
line 11
1 line 12
line 13
line 14
To this:

Code: Select all

line 1
line 2
line 3
5 line 4
line 5
line 6
line 7
5 line 8
line 9
line 10
line 11
5 line 12
line 13
line 14
-----------------------------
Use the following settings:
-----------------------------------------
[X] Regular expression
Replace All
-----------------------------------------
Configure | Preferences | Editor
[X] Use POSIX regular expression syntax
-----------------------------------------
Hope this was helpful.............good luck,
Bob
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

The OP wants to change the first character in line 4 of every file, not the first character in every 4th line of every file. That is not possible in TextPad using its rather weak regular expression engine alone. (It should be possible in WildEdit, but it's not, because of a bug (\A should match the beginning of the file, but it matches the beginning of every line).)
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Thanks for looking over my shoulder, Ben. :oops:
You are right, of course, I misread the specs.
Hope this was helpful.............good luck,
Bob
tsnik
Posts: 2
Joined: Thu Sep 17, 2009 11:34 am

Post by tsnik »

Thanks guys. Maybe I need to look for some other tool. I appreciate the input.
Post Reply