AWK inside TCL 
Author Message
 AWK inside TCL

Trying to exec. basic AWK  print command   ( awk '{print $3}' )  inside
a TCL script.
Can't  find the correct syntax to hide  $3  field portion from tcl ?


Fri, 07 Jun 2002 03:00:00 GMT  
 AWK inside TCL

Try something like:

exec echo a b c d | awk {{print $3}}

/Flemming

Quote:

> Trying to exec. basic AWK  print command   ( awk '{print $3}' )  inside
> a TCL script.
> Can't  find the correct syntax to hide  $3  field portion from tcl ?



Sat, 08 Jun 2002 03:00:00 GMT  
 AWK inside TCL
Dear all,
Hww to input Chinese into Text widget under Sun soalaris(Chinese Version)?


Sat, 08 Jun 2002 03:00:00 GMT  
 AWK inside TCL

Quote:

> Trying to exec. basic AWK  print command   ( awk '{print $3}' )  inside
> a TCL script.
> Can't  find the correct syntax to hide  $3  field portion from tcl ?

Someone told you already how to correctly escape the braces. If you
are interested, you may want to try the little script below. An
example use would be

::agft::forfile {line lno} /etc/passwd {
  set name [lindex [split $line :] 4]
  puts "Line $lno contains $name"

Quote:
}

########################################################################
#
# forfile - Iterate over lines of a file
#
# SYNOPSIS
#    forfile varnames filename body
#
# This file is part of agft, my assorted goodies for Tcl.
#

#                    Fraunhofer Institut IITB
#                    Fraunhoferstr. 1
#                    76131 Karlsruhe
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# $Revision: 1.2 $, $Date: 1999/12/15 20:20:23 $
########################################################################
## source version and package require
#source [file join [file dir [info script]] version.tcl]

namespace eval ::agft {
  namespace export forfile

Quote:
}

proc ::agft::forfile {varnames filename rexp {script {}} } {

  ## If script is empty, this in fact means rexp is empty and we use
  ## whatever we find in rexp as script.
  if {![string length $script]} {
    set script $rexp
    set rexp {}
    set all 1
  } else {
    set all 0
  }

  ## link varnames to caller' frame
  switch [llength $varnames] {
    1 #relax
    2 {
      upvar [lindex $varnames 1] lno
    }
    default {
      return -code error \
          "first parameter may only have one or two elements"
    }
  }
  upvar [lindex $varnames 0] line

  ## open the file if this is not a file descriptor
  if {[catch {fconfigure $filename}]} {
    set in [open $filename r]
    set close {close $in}
  } else {
    set in $filename
    set close \#
  }

  set lno 0
  while {-1!=[gets $in line]} {
    incr lno
    ## skip unwanted lines
    if {!$all && ![eval regexp [list $rexp] [list $line]]} continue

    ## evaluate body
    set code [catch {uplevel $script} result]

    ## treat return code of body
    # Copied from tcl.h as a reminder.
    # Why does catch not return the same codes as return does, at least
    # for those predifined codes?
    # define TCL_OK          0
    # define TCL_ERROR       1
    # define TCL_RETURN      2
    # define TCL_BREAK       3
    # define TCL_CONTINUE    4      

    switch -exact -- $code {
      0 {}
      1 {
        catch {eval $close}
        global errorInfo
        puts "((($errorInfo)))[llength $errorInfo]"
        regsub "\n *\\(\"uplevel.*" $errorInfo {} errorInfo
        return -code error -errorinfo $errorInfo $result
      }
      2 {
        eval $close
        return -code return $result
      }
      3 break
      4 {}
    }
  }
  eval $close

  return {}

Quote:
}

########################################################################

--
---------------------+---------------------------------------------




Sat, 08 Jun 2002 03:00:00 GMT  
 AWK inside TCL

Quote:

> Dear all,
> Hww to input Chinese into Text widget under Sun soalaris(Chinese Version)?

try setting the system encoding to the correct one.
for example "encoding system big5" or something similar.
Some people say that it is best to do that at the very begining of the
tk script but I haven't encoutear any problems whenever I do it.
George


Sun, 09 Jun 2002 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. run awk output thru tee inside awk

2. Use External commands inside AWK program ?

3. Suggestions about turning awk inside out

4. awk: OR inside IF

5. File size inside awk

6. Executing Tcl script inside a Tcl script

7. Running Tcl Scripts inside Tcl

8. Index Values of an Array inside a Cluster inside an Array

9. Jacl -- Running Tcl Scripts inside Java

10. Jacl -- Running Tcl Scripts inside Java

11. Jacl -- Running Tcl Scripts inside Java

12. Windows search inside tcl file

 

 
Powered by phpBB® Forum Software