This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

exec awk problem

Help for those learning Tcl or writing their own scripts.
Post Reply
B
BCyo+8C4
Voice
Posts: 24
Joined: Sun Sep 03, 2006 11:11 am

exec awk problem

Post by BCyo+8C4 »

Hi,
I'd like to call awk from a tcl script, but for some reason it doesn't work. No error message returned.

In my tcl I have this line to call the script:

Code: Select all

exec awk -f alfa.awk -v was='{tr}{td}$mask' bans-$chan.txt > bans-$chan-tmp.txt
All parameters are send to the script correctly and the awk command works fine like this when called from bash.
Changing the script to point to an invalid .awk file makes it throw an error, so it seems awk is actually run. It just doesn't do what it's supposed to do when called from tcl.

Anyone got an idea what I got wrong?
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

escape curly braces with backslashes
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
B
BCyo+8C4
Voice
Posts: 24
Joined: Sun Sep 03, 2006 11:11 am

Post by BCyo+8C4 »

the problem is not the brackets, even this test code doesn't work when called from tcl:

Code: Select all

exec awk -f alfa.awk -v was='test' bans-#test.txt > bans-#test-tmp.txt
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

my guess is that space between the redirection character and output file name is not being interpreted as in shell

try without it, i.e. >bans-$chan-tmp.txt
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Tcl Built-In Commands - exec manual page

If an arg (or pair of args) has one of the forms described below then it is used by exec to control the flow of input and output among the subbprocess(es). Such arguments will not be passed to the subprocess(es). In forms such as ``< fileName'' fileName may either be in a separate argument from ``<'' or in the same argument with no intervening space (i.e. ``<fileName'').


> fileName
Standard output from the last command is redirected to the file named fileName, overwriting its previous contents.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

BCyo+8C4 wrote:the problem is not the brackets, even this test code doesn't work when called from tcl:

Code: Select all

exec awk -f alfa.awk -v was='test' bans-#test.txt > bans-#test-tmp.txt
Just curious, what does your awk script try to accomplish and why could it not be done in native tcl code?
B
BCyo+8C4
Voice
Posts: 24
Joined: Sun Sep 03, 2006 11:11 am

Post by BCyo+8C4 »

got it. it was the ' chars + the space after >

working code:

Code: Select all

exec awk -f alfa.awk -v was={tr}{td}$mask bans-$chan.txt >bans-$chan-tmp.txt
exec mv bans-$chan-tmp.txt bans-$chan.txt
Post Reply