Page 1 of 1

Replace first character on fourth line in every file

Posted: Thu Sep 17, 2009 11:43 am
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.

Posted: Thu Sep 17, 2009 6:05 pm
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
-----------------------------------------

Posted: Thu Sep 17, 2009 7:30 pm
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).)

Posted: Thu Sep 17, 2009 8:46 pm
by Bob Hansen
Thanks for looking over my shoulder, Ben. :oops:
You are right, of course, I misread the specs.

Posted: Thu Sep 17, 2009 9:23 pm
by tsnik
Thanks guys. Maybe I need to look for some other tool. I appreciate the input.