#76931 - 2003-09-30 10:09 PM
Replace with nothing or NULL
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Trying to build a replacer to look for "" in files to be replaced with "" or a NULL Char.
So, for example, if there are a series of "", like -
We want the squares removed as well as the @CRLF. In the file there is a HEX 0D0A, so it is a @CRLF.
code:
BREAK ON ?"Checking for loan file" SLEEP 1 $handler="R:\WHANDLER\DATA\" $bkloc="R:\WHANDLER\BADLOANS\" $tspace="R:\WHANDLER\BADLOAN-WK\" $loan="C:\10133442.1" $loan=SPLIT($loan,"\")[1] ?$loan IF 0=EXIST($bkloc+$loan) ?"Copying original file to - "+$bkloc COPY "C:\"+$loan $bkloc ENDIF IF 0=EXIST($tspace+$loan) ?"Copying file into a Temporary Workspace to - "+$tspace COPY "C:\"+$loan $tspace ENDIF
SLEEP 2
$wkfil=$tspace+$loan $wkfil1=$tspace+$loan+"A" IF 0=EXIST($wkfil1) COPY $wkfil $wkfil1 ENDIF GET $ IF Open(1,$wkfil) ENDIF IF Open(2,$wkfil1,5) ENDIF $line=ReadLine(1) WHILE (@error = 0) SELECT CASE $line=" "+@crlf IF (WriteLine(2,"") <> 0) ENDIF CASE $line=INSTR($line,"") IF (WriteLine(2,"") <> 0) ENDIF ENDSELECT $line=ReadLine(1) LOOP close(1) close(2) ? "complete" COPY $wkfil1 $wkfil /h DEL $wkfil1 ?"Please check your loan: "+$loan SLEEP 2
Thanks,
Kent
|
|
Top
|
|
|
|
#76934 - 2003-09-30 10:31 PM
Re: Replace with nothing or NULL
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
See my RegEx post. If you know the ASCII values you should be able to quickly change them to some other ASCII character.
If KiXtart is the limitation, I cqan provide you a solution not using KiX. [ 30. September 2003, 22:31: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#76935 - 2003-09-30 10:36 PM
Re: Replace with nothing or NULL
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Want to replace with a "" or nothing..
Hmmm
Kent
|
|
Top
|
|
|
|
#76936 - 2003-09-30 11:28 PM
Re: Replace with nothing or NULL
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Ok..
Starting over.. Taking Howard's code, we see (not working - yet):
code:
cls break on ;$a = "1 Today 8:15 PM pdi.exe" $a='' ;;$b=''
$o = createobject("VBscript.RegExp") $o.Global = 1 ;$o.Pattern = '(\d+)\s+([\S]+)\s+(\d+:\d+\s\w+)\s+([^\s]+)' ;digit ;space ;any char ;space ;digit ;\word $o.Pattern = '([\S\+)' for each $b in $o.Execute($a) for $i=0 to 1 ? $b.SubMatches($i) next next $o=0 get $
Thanks,
Kent
|
|
Top
|
|
|
|
#76937 - 2003-09-30 11:34 PM
Re: Replace with nothing or NULL
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
BTW, looking at the square box is hex 0x20 0x1B.
Kent
|
|
Top
|
|
|
|
#76939 - 2003-09-30 11:45 PM
Re: Replace with nothing or NULL
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
You can use my Qreplace.exe from web site.
Octal character replacement:
qreplace test.kix "\050" ""
or hex
qreplace test.kix "\x29" ""
[edit] THESE EXAMPLES REMOVE LEFT AND THEN RIGHT PARENS FROM A FILE.
See http://asciitable.com
[/edit] [ 01. October 2003, 00:08: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#76940 - 2003-10-01 12:08 AM
Re: Replace with nothing or NULL
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Ok..
I can see this will probably work well for us..
We'll probably need to do both of the following: QREPLACE "R:\whandler\badloan-wk\10133442.1" "\x20\x1B\x0D\0A" "" QREPLACE "R:\whandler\badloan-wk\10133442.1" "\x20\x1B" ""
Kent
|
|
Top
|
|
|
|
#76941 - 2003-10-01 12:13 AM
Re: Replace with nothing or NULL
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
You missed an "x" in the first example:
try:
QREPLACE "R:\whandler\badloan-wk\10133442.1" "\x20\x1B|\x0D\x0A" ""
to remove all occurrances of \x20\x1B or \x0D\x0A
Catch me on MSN if you have specific questions. [ 01. October 2003, 00:27: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#76942 - 2003-10-01 06:24 AM
Re: Replace with nothing or NULL
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Howard,
Thanks for the pointers.
I will let you know the outcome.
Kent
|
|
Top
|
|
|
|
#76943 - 2003-10-01 01:56 PM
Re: Replace with nothing or NULL
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I just noticed something in the source code of qreplace. Please let me know if the filespec wildcards work or not for you. They worked for me in testing, but the function that enables them may have been part of the Perl installation and not included in the EXE.
|
|
Top
|
|
|
|
#76945 - 2003-10-01 02:52 PM
Re: Replace with nothing or NULL
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
quote: Anyway, thanks.. I was just looking for a unix "tr" work-alike for a similar situation.
So get one. There are quite a few ports of textutils, fileutils and so-on available on the web.
Look at the MinGW site for compiler related tools, or the superb GnuWin32 site which has a large number of ports. Life would be far harder if I had to get along without sed, gawk, grep and a decent "find".
|
|
Top
|
|
|
|
#76946 - 2003-10-01 05:11 PM
Re: Replace with nothing or NULL
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Ok..
Still not quite there..
Here is what we have at this point:
code:
$tspace="R:\WHANDLER\BADLOAN-WK\" $loan="C:\10133442.1" SHELL '%COMSPEC% /C qreplace.EXE '+chr(34)+$tspace+$loan+chr(34)+' "\x20\x1B\x0D\x0A" ""'
If I use \x1B, it finds 791 to replace.
There are two things I need to do:
(1) Remove the Space, Box, CRLF like the following:
We have also had a couple instances of -
(2) Remove any instance of
The biggest issue is not finding the box, but rather remove the @CRLF too.
Kent
|
|
Top
|
|
|
|
#76947 - 2003-10-01 08:23 PM
Re: Replace with nothing or NULL
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Thank you for causing me to learn something today.
It appears that when Perl slurps in an entire file, the \x0D characters are ommitted.
Please try a test where the find string does not include the \x0D character: ex. "\x20\x1B\x0A".
|
|
Top
|
|
|
|
#76948 - 2003-10-01 08:25 PM
Re: Replace with nothing or NULL
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I will update the code in the near future to read the file in BINMODE which will include the \x0D characters (and possibility some other characters). Until then let me know if you are successful with the post above. [ 01. October 2003, 20:27: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#76949 - 2003-10-01 09:25 PM
Re: Replace with nothing or NULL
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
To match one or more occurances of your \x1B character try using this string "\x20\x1B+\x0A".
The plus sign will make the RegEx engine match one or more of the preceding character.
So for a single pass you may use something like: "\x20\x1B+\x0A|\x1B+"
In my initial testing the RegEx engine properly found the longer string first. Your milage may vary.
|
|
Top
|
|
|
|
#76950 - 2003-10-01 09:29 PM
Re: Replace with nothing or NULL
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Hoby,
Good stuff! It works like a champ!
code:
BREAK ON ?"Checking for loan file" SLEEP 1 $handler="R:\WHANDLER\DATA\" $bkloc="R:\WHANDLER\BADLOANS\" $tspace="R:\WHANDLER\BADLOAN-WK\" ?"PLEASE CLOSE OUT OF THE LOAN, AND IF NEEDED, THE LOAN HANDLER - FIRST!" ? ?"Type in the loan number, e.g. 1000133442" ?">" GETS $loan ;INPUT($loan) ?"Is this a .1 or .2 file? Enter in .1, for example" ?">" GETS $ext ;INPUT($ext) $loan="10"+RIGHT($loan,6)+$ext ?$loan IF 0=EXIST($bkloc+$loan) ?"Copying original file to - "+$bkloc COPY $handler+$loan $bkloc IF 0=EXIST($tspace+$loan) ?"Copying file into a Temporary Workspace to - "+$tspace COPY $handler+$loan $tspace SHELL '%COMSPEC% /C qreplace.EXE '+chr(34)+$tspace+$loan+chr(34)+' "\x20\x1B+\x0A" ""' SHELL '%COMSPEC% /C qreplace.EXE '+chr(34)+$tspace+$loan+chr(34)+' "\x1B" ""' ;MOVE $tspace+$loan $handler ; will be uncommented when code is tested and complete ?"Please check your loan: "+$loan ENDIF ELSE ?"Loan file already exists.." ?"Please call the Support Desk for further assistance" ?"Speed Dial #nn" ENDIF ?"Process is complete" SLEEP 2
FUNCTION INPUT($str) GETS $str IF $str="" "PLEASE ENTER SOMETHING!"? INPUT($str) ENDIF ENDFUNCTION
Thanks,
Kent [ 02. October 2003, 04:45: Message edited by: kdyer ]
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(StuTheCoder)
and 798 anonymous users online.
|
|
|