Remove the same line from multiple files?
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
Remove the same line from multiple files?
Hello!
I've got over 100 files which all need line 29 removed. The catch is that line 29 is each document is different, so a simple search and replace accross all files will not work.
The good thing is that it's the same line on all documents. I just can't figure out the correct way for TextPad remove that line number across all the files.
Thanks in advance!
-Pete
I've got over 100 files which all need line 29 removed. The catch is that line 29 is each document is different, so a simple search and replace accross all files will not work.
The good thing is that it's the same line on all documents. I just can't figure out the correct way for TextPad remove that line number across all the files.
Thanks in advance!
-Pete
Actually, you could do it with search and replace by making use of \i to generate sequence numbers. For example:
- Make a backup of your files, just in case this goes wrong!
- Drag all the files into a Textpad window (to open them all).
- Press F8 to open the search dialog and check the radio button 'All Documents'.
- Search for $ and replace with xkz\i. (You will be asked to confirm that you want to apply this to all documents)
- Search for .*xkz29$\n and replace with nothing (this deletes line 29).
- Search for xkz[0-9]+$ and replace with nothing (this will remove the crap at the end of all the other lines that was introduced by the first search and replace).
- Close Textpad and choose 'Save All'.
Cool, glad it worked for you!
One thought though, if you have to do this again in the future you may want to replace the search in line 5 from .*xkz29$\n to \n.*xkz29$ (to ensure it will be deleted) if there is any possiblity that line 29 is the last line. If the files are always over 29 lines or if you won't need to do this again, then no need to worry!
One thought though, if you have to do this again in the future you may want to replace the search in line 5 from .*xkz29$\n to \n.*xkz29$ (to ensure it will be deleted) if there is any possiblity that line 29 is the last line. If the files are always over 29 lines or if you won't need to do this again, then no need to worry!
You could also do this with Wildedit despite the fact that it does not (appear to) support generating squence numbers.
- Search for .* and replace with tkx$0
- Search for ^tkx.*?\r\n(.*?\r\n){27} and replace with $0tkx.
- Search for \r\ntkx.*?$ and replace with nothing.
- Search for ^tkx and replace with nothing.
Last edited by ruari on Wed Jul 12, 2006 12:29 pm, edited 2 times in total.
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
ben_josephs, very nice, I bow before you!
Just a thought. If you usually have the option " '.' does not match a newline character" switched off you could use non-greedy repeats to avoid having to toggle it on first and off after you are done. e.g. ((?:.*?\r\n){28})(.*?\r\n)(.*) as the search. This also makes the regex shorter as you can simplify the end part.
That said I must admit I don't actually understand how '?:' bit works (although it certainly does work on a couple of test files). Would you care to break it down for this mere mortal?
Just a thought. If you usually have the option " '.' does not match a newline character" switched off you could use non-greedy repeats to avoid having to toggle it on first and off after you are done. e.g. ((?:.*?\r\n){28})(.*?\r\n)(.*) as the search. This also makes the regex shorter as you can simplify the end part.
That said I must admit I don't actually understand how '?:' bit works (although it certainly does work on a couple of test files). Would you care to break it down for this mere mortal?
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
I'm glad you found the opportunity to look up something useful.
As for non-greedy repeats, you're right, and that style is possibly faster, too, as it enables the recogniser to avoid some back-tracking. It's a matter fo taste, really. I'm so used to dot not matching newlines (at least within TextPad), and so used to the rule that the longest match (usually) wins, that I tend to do this sort of thing the old way without thinking about it.
I don't use WildEdit, by the way, as its functionality isn't incorporated into TextPad. I use Perl for the sort of thing that I might otherwise use WildEdit for. I just dig it out occasionally to check answers to questions about its style of regex.
As for non-greedy repeats, you're right, and that style is possibly faster, too, as it enables the recogniser to avoid some back-tracking. It's a matter fo taste, really. I'm so used to dot not matching newlines (at least within TextPad), and so used to the rule that the longest match (usually) wins, that I tend to do this sort of thing the old way without thinking about it.
I don't use WildEdit, by the way, as its functionality isn't incorporated into TextPad. I use Perl for the sort of thing that I might otherwise use WildEdit for. I just dig it out occasionally to check answers to questions about its style of regex.
Will textpad incorporate Wildedit?
Yes, I'm sure that will come in handy in the future.ben_josephs wrote:I'm glad you found the opportunity to look up something useful.
That's very nice of you!ben_josephs wrote:I don't use WildEdit, by the way, as its functionality isn't incorporated into TextPad. I use Perl for the sort of thing that I might otherwise use WildEdit for. I just dig it out occasionally to check answers to questions about its style of regex.
I'm very new to these forums, despite the fact that I have used Textpad for years, so applogies in advance if this is the type of question that is asked all the time, but is the expectation of most users that Wildedit's functionailty will be rolled into a future version of Textpad?
Personally, I think it would make sense for Textpad to assume all of Wildedit's capabilities. People would still buy Wildedit who needed some Textpad goodness to complement other lesser editors they use. It could be an introduction into the world of Textpad. Wildedit would then be Textpad's little brother. As it is now you have two products that have crossover functionality and are each better at doing some things than the other. It's kind of a weird setup.