Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Printing coloumns of a file using tcl

353 views
Skip to first unread message

gpa...@gmail.com

unread,
Aug 21, 2021, 1:46:08 PM8/21/21
to
Dear Experts,

I am able to print the required columns in an output file with awk command using following command in a .SH file
awk '{ print $1,$2,$5,$6 }' input_file1 > output_file2

I want achieve the same thing using tcl command
But when i used following command in a .TCL, file it throws the following error
exec awk '{ print $1,$2,$5,$6 }' input_file1 > output_file2
can't read "1": no such variable

Could you please give me a correct syntax for the above issue?

Thanks
Parth

Christian Gollwitzer

unread,
Aug 21, 2021, 2:01:43 PM8/21/21
to
Am 21.08.21 um 19:46 schrieb gpa...@gmail.com:
It'S because '' are quotes in the shell for verbatim quoting, whereas in
Tcl they are not quites at all - hence Tcl tries to substitute the "$1".
You can do verbatim quoting in Tcl using the {} braces instead.
Alternatively, you can rewrite this functionality in Tcl.

See also: https://wiki.tcl-lang.org/page/awk

Christian

Rich

unread,
Aug 21, 2021, 2:02:26 PM8/21/21
to
gpa...@gmail.com <gpa...@gmail.com> wrote:
> Dear Experts,
>
> I am able to print the required columns in an output file with awk
> command using following command in a .SH file
> awk '{ print $1,$2,$5,$6 }' input_file1 > output_file2
>
> I want achieve the same thing using tcl command
> But when i used following command in a .TCL, file it throws the following error
> exec awk '{ print $1,$2,$5,$6 }' input_file1 > output_file2
> can't read "1": no such variable

But you didn't use a Tcl command. You simply attempted to call awk
from Tcl.

> Could you please give me a correct syntax for the above issue?

Escape the dollar signs, they signal variable interpolation to the Tcl
parser.

Torsten Berg

unread,
Sep 23, 2021, 7:19:16 AM9/23/21
to
You could take a look at SQAWK (https://github.com/dbohdan/sqawk) which is a Tcl implementation of an AWK-like program. Maybe you can get ideas from there or tweak it to work as a package instead of calling it externally as a CLI program.
0 new messages