Recently at work we had this trainee that created quite a few unnecessary files in her project, I'm on the process of cleaning up the project to try and salvage it,however, I'm on a bit of trouble.
For example, I want to delete the following lines of code from all the files in the project (thankfully they're consistent):
<?php
include('includes/footer.php');
?>
I'm open to do this on eclipse or sed, I've tried with both to no avail, I've already done in another project where I delete the include line using sed, but then I end up with a bunch of empty php tags, I hope you guys can help me find a solution that I can just use and keep in mind going forward.
Thanks
sed is for simple substitutions on a single line. For anything spanning multiple lines, use awk. This is using GNU awk for multi-char RS:
$ cat file
foo
<?php
include('includes/footer.php');
?>
bar
$ awk -v RS="^$" -v ORS="" '{sub(/<[?]php
include[(]\047includes[/]footer.php\047[)];
[?]>
/,"")}1' file
foo
bar
In the search RE, it uses []
around RE metacharacters so they are treated as literal characters, and uses \047
for the single quotes '
since you can't use a single quote within a script that's delimited with single quotes.
Use Search dialog. Select the project in Package/Project/Navigator view then press Ctrl + H
Enter the regular expression as shown in pic. Also note that I have chosen Selected resources option and selected com.chandrayya....
project in package explorer.
Press Search button. You will get all the results in Search view.
Activate search view and press collapse all button to collapse all search results then press Ctrl + A to select all search results in search view. Right click on the selection and choose Replace All..
option then you will get a dialog box as shown below. Enter once space character in With text box and press OK button.