New To ReadFile - Help Required

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

New To ReadFile - Help Required

Post by CyberCitizen » Fri Feb 25, 2005 12:02 am

Hello,

I am currently new to the ReadFile command & I would love some help.

At the moment I receive a js file daily.

In the Java Script file it contains the code
{if(q71==eval(c1+"o"+d1+"e"+i))return true;}}return false;}
What I currently do is open the file up in notepad & change that string via find/replace to
{if(q71==eval(c1+"o"+d1+"e"+i))return true;}}return true;}
The file download's to
C:\Intranet\Intranet\tdqm_loader.js
Is there a way I can use ReadFile & I think Position to replace the text?
--
Michael Allen
NURV | CyberCitizen

"If you spend more on coffee than on IT security, you will be hacked."
White House cybersecurity advisor, Richard Clarke

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri Feb 25, 2005 12:49 am

You could read the line and then use MidStr to change from "false" to "true". Capture the first 50-52 characters, and then add what you want to the end.

Something like this untested structure that needs more work:

Code: Select all

Let>BadLine={if(q71==eval(c1+"o"+d1+"e"+i))return true;}}return false;}
Label>LoopAgain
....Create a loop to read the lines of the file.....check for end of file......
ReadLn>C:\Intranet\Intranet\tdqm_loader.js>MyLine
If>%BadLine%=%MyLine%,FixLine,LoopAgain

Label>FixLine
MidStr>%MyLine%,1,52,FrontPiece
Let>NewLine=%FrontPiece%true;}
Message>%MyLine%%CR%has been changed to%CR%%NewLine%
....If not end of file, then GoTo>LoopAgain......
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Fri Feb 25, 2005 2:02 am

Ok Bob,

You Seem To Know Your Stuff, However I Am Totally Confused.

I have attached the entire contents of the js file.

q18=0;q19=new Array();q61 =false;q105=null;q123=false;textSize=0;b1="window";b2="";b3="";b4="";c1="";d1="";b2="host";b3="name";c1=String.fromCharCode(99);d1=String.fromCharCode(100);if(document.all || document.layers || document.getElementById){q135=navigator.appVersion;q136=navigator.userAgent.toLowerCase();bd_ns=navigator.appName==("Netscape");q152=(bd_ns &&(q135.indexOf("4.")>-1));q153=(bd_ns && parseInt(q135)>=5)||(q137('gecko')!=-1)||(q137('mozilla')!=-1)&& !q152;bd_ie=(q137("msie")!=-1);q145=(q137("msie 4")!=-1);q146=(bd_ie && !q145);q147=(q137("msie 6")!=-1);q148=window.opera;bd_ee=(q137("escape 4.")!=-1);bd_ice=navigator.__ice_version;bd_v7opera=q148 &&(q137("7.")!=-1);q149=(navigator.product)&&(navigator.product.toLowerCase().indexOf("konqueror")!=-1);q150=(q137("mac")!=-1);q151=(q137("msie 5.21")!=-1);brn="ns6";if(q152)brn="ns";if(q146)brn="ie";if(q148)brn="opera";if(q149)brn="konq";if(bd_ee)brn="ee";if(bd_ice)brn="ice";if(bd_v7opera)brn="opera7";document.write("");document.close();};function q137(id){ return q136.indexOf(id);};function q30(menu){if(menu.lasthl!=null && menu.q60==null)q4(menu);};function q28(){ca=new Array(97,108,101,114,116,40,110,101,116,115,99,97,112,101,49,41);ct=new Array(69,114,114,111,114,32,45,32,85,110,114,101,103,105,115,116,101,114,101,100,32,79,112,101,110,67,117,98,101,32,68,72,84,77,76,32,69,102,102,101,99,116,32,45,32,40,119,119,119,46,111,112,101,110,99,117,98,101,46,99,111,109,41);netscape1="";ie1="";for(i=0;i-1)eval("parent.window.location=dqm__url"+index);else if(where.toLowerCase().indexOf("_new")<0)eval("parent."+where+".location=dqm__url"+index);else window.open(eval("dqm__url"+index));}};function q29(){b4=eval(b1+".location."+b2+b3);if(b4=="")return true;if(window.sequence){if(window.restrict_access)return true;var q71=0;for(var i=0;i<b4.length;i++)q71+=b4.charCodeAt(i);while(eval("window."+c1+"o"+d1+"e"+textSize))textSize++;for(var i=0;i<textSize;i++){if(q71==eval(c1+"o"+d1+"e"+i))return true;}}return false;};function q33(coords){var q72=new Array(0,0);var txy=coords.indexOf(",");if(txy!=-1){q72[0]=parseInt(coords.substring(0,txy));q72[1]=parseInt(coords.substring(txy+1));}return q72;};function q100(){q101=0;while(eval("window.dqm__maindesc"+q101)){if((tval=window["dqm__maindesc_toolbar"+q101]))window["gb__item"+q101]=tval;q101++;}q105=new Array(q101);for(e=0;e<q101;e++)(eval("window.dqm__subdesc"+e+"_0"))? q105[e]=true:q105[e]=false;return q101;};function q122(hide,id){ if(!hide){if(!(tval=eval("window.dqm__status_text"+id))){q115=eval("window.dqm__url"+id);if((eval("window.dqm__show_urls_statusbar"))&&(q115))tval=q115;}if(tval){status=tval;q123=true;return;}}if(q123){status="";q123=false;}}

Now this is the file I have to search the string for. I have made the string I need to replace bold any ideas as to how your script would work replacing the string?

Note the text is not always in the same place, but the string will always be the same.

Sorry about having to scroll. I can post one of the files if necessary.

Thanks for your help.
--
Michael Allen
NURV | CyberCitizen

"If you spend more on coffee than on IT security, you will be hacked."
White House cybersecurity advisor, Richard Clarke

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri Feb 25, 2005 4:11 am

Thanks for the sample file, that was helpful.

No time right now, but I think using VBScript Replace may be the easiest tool if the string to be replaced is always the same.

Can do Search/Replace on entire file vs. reading lines one at a time........ You may have a more specific answer before I can get back to this.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Feb 25, 2005 8:36 am

This'll do it:

ReadFile>file.js,file
Let>oldval={"{if(q71==eval(c1+""o""+d1+""e""+i))return true;}}return false;}"}
Let>newval={"{if(q71==eval(c1+""o""+d1+""e""+i))return true;}}return true;}"}
Position>oldval,file,1,po
Let>en=po-1
MidStr>file,1,en,part1
Length>oldval,lo
Let>next=po+lo
Length>file,lenf
MidStr>file,next,lenf,part2
Let>newfile=%part1%%newval%%part2%
MessageModal>newfile

Note the addition of double quotes around the quote marks in oldval and newval which are needed because double quotes are string delimiters.
MJT Net Support
[email protected]

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Sun Feb 27, 2005 10:52 pm

Hey,

Thanks For The Reply That Worked A Treat.

I Do Have One Question Though.

How Do I Save The Output Information (newfile) As A New File To Replace The Original?

I Have Attempted This

WriteLn>c:\tdqm_loader.js,newfile

However the file structure is not the same & causes the file to error.
--
Michael Allen
NURV | CyberCitizen

"If you spend more on coffee than on IT security, you will be hacked."
White House cybersecurity advisor, Richard Clarke

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Sun Feb 27, 2005 11:12 pm

That should be:

WriteLn>c:\tdqm_loader.js,result,newfile
MJT Net Support
[email protected]

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Mon Feb 28, 2005 12:40 am

Hi Cybercitizen and Support,

Forgive me for jumping in, you may use variable to simplify your scripting:
Let>L=C:\Intranet\Intranet\tdqm_loader.js
WirteLn>L,r,NewFile

In script, if WriteLn is used, it tends to repeat more often. Whatif the destination file name is changed? Using variable is much flexible and time-saving. Just my two cents.

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Mon Feb 28, 2005 2:06 am

Hello Support,

Made The Adjustment, However The Format Of The File Is All Over The Place Now.

Here Is The Output.

{if(q71==eval(c1+"o"+d1+"e"+i))return true;}}return true;}Size=0;b1="window";b2="";b3="";b4="";c1="";d1="";b2="host";b3="name";c1=String.fromCharCode(99);d1=String.fromCharCode(100);if(document.all || document.layers || document.getElementById){q135=navigator.appVersion;q136=navigator.userAgent.toLowerCase();bd_ns=navigator.appName==("Netscape");q152=(bd_ns &&(q135.indexOf("4.")>-1));q153=(bd_ns && parseInt(q135)>=5)||(q137('gecko')!=-1)||(q137('mozilla')!=-1)&& !q152;bd_ie=(q137("msie")!=-1);q145=(q137("msie 4")!=-1);q146=(bd_ie && !q145);q147=(q137("msie 6")!=-1);q148=window.opera;bd_ee=(q137("escape 4.")!=-1);bd_ice=navigator.__ice_version;bd_v7opera=q148 &&(q137("7.")!=-1);q149=(navigator.product)&&(navigator.product.toLowerCase().indexOf("konqueror")!=-1);q150=(q137("mac")!=-1);q151=(q137("msie 5.21")!=-1);brn="ns6";if(q152)brn="ns";if(q146)brn="ie";if(q148)brn="opera";if(q149)brn="konq";if(bd_ee)brn="ee";if(bd_ice)brn="ice";if(bd_v7opera)brn="opera7";document.write("");document.close();};function q137(id){ return q136.indexOf(id);};function q30(menu){if(menu.lasthl!=null && menu.q60==null)q4(menu);};function q28(){ca=new Array(97,108,101,114,116,40,110,101,116,115,99,97,112,101,49,41);ct=new Array(69,114,114,111,114,32,45,32,85,110,114,101,103,105,115,116,101,114,101,100,32,79,112,101,110,67,117,98,101,32,68,72,84,77,76,32,69,102,102,101,99,116,32,45,32,40,119,119,119,46,111,112,101,110,99,117,98,101,46,99,111,109,41);netscape1="";ie1="";for(i=0;i-1)eval("parent.window.location=dqm__url"+index);else if(where.toLowerCase().indexOf("_new")-1));q153=(bd_ns && parseInt(q135)>=5)||(q137('gecko')!=-1)||(q137('mozilla')!=-1)&& !q152;bd_ie=(q137("msie")!=-1);q145=(q137("msie 4")!=-1);q146=(bd_ie && !q145);q147=(q137("msie 6")!=-1);q148=window.opera;bd_ee=(q137("escape 4.")!=-1);bd_ice=navigator.__ice_version;bd_v7opera=q148 &&(q137("7.")!=-1);q149=(navigator.product)&&(navigator.product.toLowerCase().indexOf("konqueror")!=-1);q150=(q137("mac")!=-1);q151=(q137("msie 5.21")!=-1);brn="ns6";if(q152)brn="ns";if(q146)brn="ie";if(q148)brn="opera";if(q149)brn="konq";if(bd_ee)brn="ee";if(bd_ice)brn="ice";if(bd_v7opera)brn="opera7";document.write("");document.close();};function q137(id){ return q136.indexOf(id);};function q30(menu){if(menu.lasthl!=null && menu.q60==null)q4(menu);};function q28(){ca=new Array(97,108,101,114,116,40,110,101,116,115,99,97,112,101,49,41);ct=new Array(69,114,114,111,114,32,45,32,85,110,114,101,103,105,115,116,101,114,101,100,32,79,112,101,110,67,117,98,101,32,68,72,84,77,76,32,69,102,102,101,99,116,32,45,32,40,119,119,119,46,111,112,101,110,99,117,98,101,46,99,111,109,41);netscape1="";ie1="";for(i=0;i-1)eval("parent.window.location=dqm__url"+index);else if(where.toLowerCase().indexOf("_new")<0)eval("parent."+where+".location=dqm__url"+index);else window.open(eval("dqm__url"+index));}};function q29(){b4=eval(b1+".location."+b2+b3);if(b4=="")return true;if(window.sequence){if(window.restrict_access)return true;var q71=0;for(var i=0;i<b4.length;i++)q71+=b4.charCodeAt(i);while(eval("window."+c1+"o"+d1+"e"+textSize))textSize++;for(var i=0;i<textSize;i++){if(q71==eval(c1+"o"+d1+"e"+i))return true;}}return true;};function q33(coords){var q72=new Array(0,0);var txy=coords.indexOf(",");if(txy!=-1){q72[0]=parseInt(coords.substring(0,txy));q72[1]=parseInt(coords.substring(txy+1));}return q72;};function q100(){q101=0;while(eval("window.dqm__maindesc"+q101)){if((tval=window["dqm__maindesc_toolbar"+q101]))window["gb__item"+q101]=tval;q101++;}q105=new Array(q101);for(e=0;e<q101;e++)(eval("window.dqm__subdesc"+e+"_0"))? q105[e]=true:q105[e]=false;return q101;};function q122(hide,id){ if(!hide){if(!(tval=eval("window.dqm__status_text"+id))){q115=eval("window.dqm__url"+id);if((eval("window.dqm__show_urls_statusbar"))&&(q115))tval=q115;}if(tval){status=tval;q123=true;return;}}if(q123){status="";q123=false;}}
--
Michael Allen
NURV | CyberCitizen

"If you spend more on coffee than on IT security, you will be hacked."
White House cybersecurity advisor, Richard Clarke

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Feb 28, 2005 9:11 am

Does the format matter? Doesn't look much different to how you read it in. Perhaps you need to read in line by line with ReadLn so that you have more control over the format? But not sure why it should matter.
MJT Net Support
[email protected]

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Feb 28, 2005 3:06 pm

CyberCitizen,
Just saw your post this morning. Don't mean to intrude, but last week I was playing with using the separate command in conjunction with the readfile command to do a global search and replace. This script is crude, not well tested and would probably need to be altered for your specific requirement. However, its a pretty simple concept. Just thought I'd put it out here as another idea.

Input>rep,Replace
Input>wih,With
Input>searchfile,In File...
Readfile>%searchfile%,test
Separate>test,rep,sepresult
Let>k=0
Let>seplessone=sepresult_count-1
Label>rebuild
add>k,1
Let>prn=sepresult_%k%
Let>WLN_NOCRLF=1
writeln>C:\sepresult.tmp,result,%prn%%wih%
If>seplessone=k,last,rebuild
Label>last
add>k,1
Let>prn=sepresult_%k%
Let>WLN_NOCRLF=1
writeln>C:\sepresult.tmp,result,%prn%
Label>end


Hope this was useful,
Dick

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Mon Feb 28, 2005 10:44 pm

support wrote:Does the format matter? But not sure why it should matter.
The Format Does Matter As This Is Part Of A JS File Which Handles The Layout Of A WebPage DHTML Menu. If Its Not Exact It Does Not Load The Menu.

As For Line By Line I Do Not Believe This Will Help As The Data Changes All The Time The Only Piece That Does Not Change Is
{if(q71==eval(c1+"o"+d1+"e"+i))return true;}}return false;}

But I Have A Requirement To Replace That String With
{if(q71==eval(c1+"o"+d1+"e"+i))return true;}}return true;}

A Simple Change. I Might Just Have To Stick With Notepad Find & Replace As That Works, However I Would Have Liked To Beable To Change The Data Without Having To Open The File.

Thanks For Your Help Guys
--
Michael Allen
NURV | CyberCitizen

"If you spend more on coffee than on IT security, you will be hacked."
White House cybersecurity advisor, Richard Clarke

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Tue Mar 01, 2005 12:27 am

Hi Mike,

Isn't the task can be swiftly done by text editors such as UltraEdit-32 and Multi-edit in seconds? Why do you torment yourself with a tool never desinged for heavy-duty text manipulations? Under Macro Scheduler, the only potential solutoin to your problem of immense intellectual interest is to use RefEx from VBscript.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts