| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Is there any way to call a sed command from within a Expect script? I just cannot seem to get the syntax right. This command seems to get me close to where I need to be but I can only run it after exiting from my Expect script. cat -v OFCENG_20080821.txt | sed -e 's/M-bM-^@M-^\\/"/g' -e 's/M-bM- ^@M-^]/"/g' > OFCENG_20080821B.txt This replaces invalid characters with an ^M. I do not really want the ^M but I am sure I can figure this part out later. TIA |
|
#2
| |||
| |||
| In article <ae0a279e-4fad-4cb6-8a17-96aa25486fe6@m73g2000hsh.googlegroups.com>, <jbjunk1@gmail.com> wrote: >Is there any way to call a sed command from within a Expect script? I >just cannot seem to get the syntax right. > >This command seems to get me close to where I need to be but I can >only run it after exiting from my Expect script. > > >cat -v OFCENG_20080821.txt | sed -e 's/M-bM-^@M-^\\/"/g' -e 's/M-bM- >^@M-^]/"/g' > OFCENG_20080821B.txt > >This replaces invalid characters with an ^M. I do not really want the >^M but I am sure I can figure this part out later. > >TIA Expect absolutely can run sed. While Expect can do anything sed an do, withOUT invocation of sed, I can understand the occasional convenience of passing work off to a co-operating process. Be aware that not all versions of cat(1) respect -v. If I understand you correctly, perhaps exec cat -v $IN | sed -e {s/M-bM-^@M-^\\/"/g} -e {s/M-bM-^@M-^]/"/g} > $OUT will interest you. <URL: http://phaseit.net/claird/comp.lang.tcl/fmm.html#awk > has a little more to say on this same subject. |
|
#3
| |||
| |||
| At 2008-08-25 12:00PM, "jbjunk1@gmail.com" wrote: > Is there any way to call a sed command from within a Expect script? I > just cannot seem to get the syntax right. > > This command seems to get me close to where I need to be but I can > only run it after exiting from my Expect script. > > > cat -v OFCENG_20080821.txt | sed -e 's/M-bM-^@M-^\\/"/g' -e 's/M-bM- > ^@M-^]/"/g' > OFCENG_20080821B.txt > > This replaces invalid characters with an ^M. I do not really want the > ^M but I am sure I can figure this part out later. Surely you can do this inside your expect script. call [log_file] with no arguments to turn off logging, then set logfile OFCENG_${date}.txt set in [open $logfile r] set out [open $logfile.new w] while {[gets $in line] > -1} { # replace all "funny" chars with a dot regsub -all {[^[:graph:][:blank:]]} $line "." line puts $out $line } close $in close $out file delete $logfile file rename $logfile.new $logfile -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous |
|
#4
| |||
| |||
| On Aug 25, 12:08*pm, Glenn Jackman <gle...@ncf.ca> wrote: > At 2008-08-25 12:00PM, "jbju...@gmail.com" wrote: > > > *Is there any way to call asedcommand from within a Expect script? I > > *just cannot seem to get the syntax right. > > > *This command seems to get me close to where I need to be but I can > > *only run it after exiting from my Expect script. > > > *cat -v OFCENG_20080821.txt |sed-e 's/M-bM-^@M-^\\/"/g' -e 's/M-bM- > > *^@M-^]/"/g' *> OFCENG_20080821B.txt > > > *This replaces invalid characters with an ^M. I do not really want the > > *^M but I am sure I can figure this part out later. > > Surely you can do this inside your expect script. > > call [log_file] with no arguments to turn off logging, then > > * * set logfile OFCENG_${date}.txt > > * * set in [open $logfile r] > * * set out [open $logfile.new w] > > * * while {[gets $in line] > -1} { > * * * * # replace all "funny" chars with a dot > * * * * regsub -all {[^[:graph:][:blank:]]} $line "." line > * * * * puts $out $line > * * } > * * close $in > * * close $out > > * * file delete $logfile > * * file rename $logfile.new $logfile > > -- > Glenn Jackman > * * Write a wise saying and your name will live forever. -- Anonymous Earlier in my script I am sending everything to this log set OFCENG OFCENG2_${tdate}.txt exp_log_file /var/www/NoOffice/Input/$OFCENG I brought in your section at the end of the script: set logfile $OFCENG set in [open $logfile r] set out [open $logfile.new w] while {[gets $in line] > -1} { # replace all "funny" chars with a dot regsub -all {[^[:graph:][:blank:]]} $line "." line puts $out $line } close $in close $out file delete $logfile file rename $logfile.new $logfile I do not get any erros with this but my output file still has all of special Characters: Last login: Mon Aug 25 13:42:26 from 10.32.19.172 [H[J Shouldn't these be replaced with the *.* |
|
#5
| |||
| |||
| In article <slrngb5pog.ife.glennj@smeagol.ncf.ca>, Glenn Jackman <glennj@ncf.ca> wrote: |
|
#6
| |||
| |||
| At 2008-08-25 01:53PM, "jbjunk1@gmail.com" wrote: > I brought in your section at the end of the script: > make sure you: log_file ;# to turn off logging > set logfile $OFCENG > > set in [open $logfile r] > set out [open $logfile.new w] > > while {[gets $in line] > -1} { > # replace all "funny" chars with a dot > regsub -all {[^[:graph:][:blank:]]} $line "." line > puts $out $line > } > close $in > close $out > > file delete $logfile > file rename $logfile.new $logfile > > I do not get any erros with this but my output file still has all of > special Characters: > > Last login: Mon Aug 25 13:42:26 from 10.32.19.172 > > [H[J > > Shouldn't these be replaced with the *.* -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous |
|
#7
| |||
| |||
| At 2008-08-25 02:19PM, "Cameron Laird" wrote: > In article <slrngb5pog.ife.glennj@smeagol.ncf.ca>, > Glenn Jackman <glennj@ncf.ca> wrote: > . > . > . > > set logfile OFCENG_${date}.txt > > > > set in [open $logfile r] > > set out [open $logfile.new w] > > > > while {[gets $in line] > -1} { > > # replace all "funny" chars with a dot > > regsub -all {[^[:graph:][:blank:]]} $line "." line > > puts $out $line > > } > > close $in > > close $out > > > > file delete $logfile > > file rename $logfile.new $logfile > . > . > . > Glenn, I assume you know that in many situations it's fine to > reduce line count with something like > > puts $out -nonewline [regsub -all $pattern [read $in] .] Thanks for the reminder. Largely thanks to Perl, I tend to think in a line oriented way. -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous |
|
#8
| |||
| |||
| On Aug 25, 1:49*pm, Glenn Jackman <gle...@ncf.ca> wrote: > At 2008-08-25 01:53PM, "jbju...@gmail.com" wrote: > > > *I brought in your section at the end of the script: > > make sure you: > > * * log_file *;# to turn off logging > > > > > *set logfile $OFCENG > > > * * *set in [open $logfile r] > > * * *set out [open $logfile.new w] > > > * * *while {[gets $in line] > -1} { > > * * * * *# replace all "funny" chars with a dot > > * * * * *regsub -all {[^[:graph:][:blank:]]} $line "." line > > * * * * *puts $out $line > > * * *} > > * * *close $in > > * * *close $out > > > * * *file delete $logfile > > * * *file rename $logfile.new $logfile > > > *I do not get any erros with this but my output file still has all of > > *special Characters: > > > *Last login: Mon Aug 25 13:42:26 from 10.32.19.172 > > > * [H [J > > > *Shouldn't these be replaced with the *.* > > -- > Glenn Jackman > * * Write a wise saying and your name will live forever. -- Anonymous Glen, I added the log_file above set logfile OFCENG_${date}.txt I am still getting the weird characters in the output log Example: Press <enter> to continue... [H[J Unfortunately, the Special Characters do not make it into the message board post. |
|
#9
| |||
| |||
| In article <cf79e8a6-8aa1-4043-a171-692b9722ab2a@z72g2000hsb.googlegroups.com>, <jbjunk1@gmail.com> wrote: |
|
#10
| |||
| |||
| On Aug 26, 9:43*am, JB <jbju...@gmail.com> wrote: > On Aug 26, 8:58*am, JB <jbju...@gmail.com> wrote: > > > > > On Aug 26, 8:42*am, JB <jbju...@gmail.com> wrote: > > > > On Aug 25, 4:32*pm, cla...@lairds.us (Cameron Laird) wrote: > > > > > In article <cf79e8a6-8aa1-4043-a171-692b9722a...@z72g2000hsb.googlegroups.com>,*<jbju. ..@gmail.com> wrote: > > > > > * * * * * * * * * * * * . > > > > * * * * * * * * * * * * . > > > > * * * * * * * * * * * * . > > > > > >I added the log_file above set logfile OFCENG_${date}.txt > > > > > >I am still getting the weird characters in the output log > > > > > >Example: > > > > > >Press <enter> to continue... > > > > > > [H [J > > > > > >Unfortunately, the Special Characters do not make it into the message > > > > >board post. > > > > > Something's fishy; Glenn's code *can't* print the special characters > > > > as you describe. *Is it possible, for example, that you're somehow > > > > dealing with '^' followed by 'J', rather than the non-printable > > > > rendered as '^J'? > > > > How would I modify the regsub to remove '^' as well if this is the > > > case? > > > I figured out how to add the "^" but this was not the problem. The > > problem is that the file is filled with ESC characters. > > Actually CRLF Finally, I got it. Big thanks to Glen and Cameron, you guys are awesome. Here is the final version: log_file set logfile /var/www/NoOffice/Input/$OFCENG set in [open $logfile r] set out [open $logfile.new w] while {[gets $in line] > -1} { # replace all "funny" chars with a dot regsub -all {[^[:graph:][:blank:][\x00-\x08]|[\x0A-\x0C]|[\x0E- \x1F]} $line "" line # not required, just house cleaning regsub -all {[\[H\[J]} $line "" line puts $out $line } close $in close $out file delete $logfile file rename $logfile.new $logfile Hopefully this will help others that are having the same issue. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.