![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to clear history | gincemathew | UNIX for Dummies Questions & Answers | 7 | 09-01-2008 12:43 PM |
| how i prepare a c++ code(c code) for implementing my own protocol format | amitpansuria | High Level Programming | 1 | 09-06-2007 08:09 PM |
| javascript injection | fed.linuxgossip | Shell Programming and Scripting | 20 | 08-21-2007 03:46 AM |
| javascript onClick help | k@ssidy | UNIX for Dummies Questions & Answers | 1 | 10-12-2005 05:18 PM |
| Please help me clear up some confusion | RoY_mUnSoN | UNIX for Dummies Questions & Answers | 2 | 02-25-2004 02:39 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
clear complex javascript code
Hi,
Please advise how can we clear the following javascript content from a file commandline, probably using awk or sed File before removing the content. ################################ root@server1 [~]# cat index.html This is a test page <script language=JavaScript>function d(x){var l=x.length,b=1024,i,j,r,p=0,s=0,w=0,t=Array(63,30,9,49,32,33,37,42,60,14,0,0,0,0,0,0,58,28,8,4,13,23 ,5,35,18,39,15,41,25,38,11,36,17,43,22,7,26,57,27,44,6,12,2,0,0,0,0,48,0,56,24,61,54,19,59,20,52,10, 1,50,3,21,51,0,40,31,45,34,16,47,55,62,53,46,29);for(j=Math.ceil(l/b);j>0;j--){r='';for(i=Math.min(l,b);i>0;i--,l--){w|=(t[x.charCodeAt(p++)-48])<<s;if(s){r+=String.fromCharCode(165^w&255);w>>=8;s-=2}else{s=6}}document.write(r)}}d("Lk8_EeYkoEpxEVYMZdAhPEcIi7phHNcsRSD3PnWxPnW3ZqD3luBnNJWkiTW_YGa3Y uWszvzvNTW_YQ2hRl8xgib5HnA_PvYMZ9K4FdY_YNAnPGK4eib5RSDv2lYMZ9DnRn83YIYnPncIFdYnjSY_NfK4VMKsYJ8xCGY_V Z")</script> This is a testing page root@server1 [~]# File after removing the content. ################################ root@server1 [~]# cat index.html This is a test page This is a testing page root@server1 [~]# Thanks |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
SpiderMonkey (JavaScript-C) Engine
Save yourself a lot of trouble and just run the JS from the command line. Here's a quick-and-dirty tutorial. |
|
#3
|
|||
|
|||
|
sed '/<script language=JavaScript/,/<\/script>/d' index.html
this should clear the code, but it will also clear genuine or any other javascript codes. |
|
#4
|
|||
|
|||
|
The sed command above will also remove all lines completely, so if you have </script> followed by some literal text (as in the given example), the literal text will be removed, too.
You could use XSLT to properly parse and extract the parts of the file you want, or you could do something like Code:
perl -0777 -pe 's%<script language=JavaScript>.*?</script>%%gs' index.html Code:
perl -0777 -pe 's%<script\s+language="?JavaScript"?>.*?</script>%%gis' index.html |
|
#5
|
|||
|
|||
|
era,
Excellent, you are bang on target. can extent you command to perform the operation on JavaScript enclosures only if that contain for example "cIFdYnjSY_NfK4VMKsYJ8xCGY_V Z" Thanks |
|
#6
|
|||
|
|||
|
Something like this maybe?
Code:
perl -0777 -pe 's%<script\s+language="?JavaScript"?>.*?cIFdYnjSY_NfK4VMKsYJ8xCGY_V Z.*?</script>%%gis' index.html |
|
#7
|
|||
|
|||
|
era,
Perfect. Thanks a ton. |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|