jbrashear72
asked on
quick help with grep 500
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?
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?
ASKER
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
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
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
but try following:
find /home -type f -exec perl -i.bak -pe 's/lamb/sheep/g' {} \; -print
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:
https://www.experts-exchange.com/questions/21822732/using-grep-and-awk-to-do-a-global-replace-how-do-I-do-this-NEED-HELP-ASAP-500-pts.html
HTH:)
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:
https://www.experts-exchange.com/questions/21822732/using-grep-and-awk-to-do-a-global-replace-how-do-I-do-this-NEED-HELP-ASAP-500-pts.html
HTH:)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
2. grep -rl "step57" * | gawk -F/ 'BEGIN{OFS="/"}{$NF="";pri