bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] coprocess feature not working


From: Aharon Robbins
Subject: Re: [bug-gawk] coprocess feature not working
Date: Mon, 04 Mar 2013 14:29:53 +0200
User-agent: Heirloom mailx 12.5 6/20/10

Greetings.

I did not completely follow what your scripts are attempting to do.
I suspect that buffering is an issue. You can try using

        fflush("./translate.sh")

after writing each record. If that does not work you may wish to use

        close("./translate.sh", "to")

to close the script's read pipe and then read the results back from the
script.

You may have better luck simply using the networking features in gawk
to open an HTTP connection and read the data you're looking for directly
and processing it within awk, since you're just doing some simple
sed and cut processing.

I hope this helps,

Arnold

> To: address@hidden, address@hidden
> Subject: coprocess feature not working
> From: Y Kocharekar <address@hidden>
> Date: Thu, 28 Feb 2013 11:18:53 +0530
>
> Hi
>
> i am trying to translate a bunch of text records in a file , using awk co 
> process feature to call external script to translate the text.
>
> but this approach is not working -
>
> following are details
>
>
> address@hidden trans]$ awk -W version | head -1
> GNU Awk 3.1.7
> address@hidden trans]$ uname -a
> Linux 01HW521750 2.6.32-279.el6.x86_64 #1 SMP Fri Jun 22 12:19:21 UTC 2012 
> x86_64 x86_64 x86_64 GNU/Linux
> address@hidden trans]$ ls
> cpawk.awk  small  translate.sh
> address@hidden trans]$ # "This is the input"
> address@hidden trans]$ cat small 
> "?$BEEOC"
> "?$BEEOC"
> "?$BEEOC"
>
> address@hidden trans]$ # "This is external script"
>
> address@hidden trans]$ cat translate.sh 
> #!/bin/bash
> #set -x
>
> while read input
> do
> wget -U "Mozilla/5.0" -qO - "
> http://translate.google.com/translate_a/t?client=t&text=
> "$input"&sl=auto&tl=en" | sed 's/\[\[\[\"//' | cut -d \" -f 1 >&1;
> done
>
> address@hidden trans]$ # "This is awk script"
>
> address@hidden trans]$ cat cpawk.awk 
> {
> print $0 |& "./translate.sh"
> "./translate.sh" |& getline result
> print result
> } 
> address@hidden trans]$ #external script works on its own
> address@hidden trans]$ echo "?$BEEOC" | ./translate.sh
> Phone
>
> address@hidden trans]$ # "awk script does not"
>
> address@hidden trans]$ awk -f cpawk.awk small 
> \
> \
> \
> address@hidden trans]$
>
>
> Pls let me know if this is bug in awk or i am doing something wrong.
>
> thanks,
> Yash
>
>
> =====-----=====-----=====
> Notice: The information contained in this e-mail
> message and/or attachments to it may contain 
> confidential or privileged information. If you are 
> not the intended recipient, any dissemination, use, 
> review, distribution, printing or copying of the 
> information contained in this e-mail message 
> and/or attachments to it are strictly prohibited. If 
> you have received this communication in error, 
> please notify us by reply e-mail or telephone and 
> immediately and permanently delete the message 
> and any attachments. Thank you



reply via email to

[Prev in Thread] Current Thread [Next in Thread]