Home > Archive > AWK > January 2005 > strange thing...
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Gernot Frisch 2005-01-26, 3:55 pm |
| this works:
cat a.txt|gawk '{if(length($0) ==1) {printf("%s\n", $0);}}'
and this:
cat a.txt|gawk '{if(length($0) < 1) {printf("%s\n", $0);}}'
gives error:
gawk: cmd. line:1: {if(length($0) {printf("%s\n", $0);}}
gawk: cmd. line:1: ^ syntax error
Any idea why?
Thank you.
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}
________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
| |
| Gernot Frisch 2005-01-26, 3:55 pm |
|
"Gernot Frisch" <Me@Privacy.net> schrieb im Newsbeitrag
news:35pm4lF4qa60jU1@individual.net...
> this works:
> cat a.txt|gawk '{if(length($0) ==1) {printf("%s\n", $0);}}'
>
> and this:
> cat a.txt|gawk '{if(length($0) > 1) {printf("%s\n", $0);}}'
>
> gives error:
> gawk: cmd. line:1: {if(length($0) {printf("%s\n", $0);}}
> gawk: cmd. line:1: ^ syntax error
>
> Any idea why?
I'm using a cygwin gawk: It uses the '>' as a pipe symbol and writes
the file "1".
How can I avoid this?
| |
| Kenny McCormack 2005-01-26, 3:55 pm |
| In article <35pnheF4pnqscU1@individual.net>,
Gernot Frisch <Me@Privacy.net> wrote:
>
>"Gernot Frisch" <Me@Privacy.net> schrieb im Newsbeitrag
>news:35pm4lF4qa60jU1@individual.net...
>I'm using a cygwin gawk: It uses the '>' as a pipe symbol and writes
>the file "1".
>
>How can I avoid this?
Install Linux.
| |
| Doug McClure 2005-01-26, 3:55 pm |
| Missing ")"
DKM
On Wed, 26 Jan 2005 15:02:56 +0100, "Gernot Frisch" <Me@Privacy.net>
wrote:
>this works:
>cat a.txt|gawk '{if(length($0) ==1) {printf("%s\n", $0);}}'
>
>and this:
>cat a.txt|gawk '{if(length($0) < 1) {printf("%s\n", $0);}}'
>
>gives error:
>gawk: cmd. line:1: {if(length($0) {printf("%s\n", $0);}}
>gawk: cmd. line:1: ^ syntax error
>
>Any idea why?
>
>Thank you.
To contact me directly, send EMAIL to (single letters all)
DEE_KAY_EMM AT EarthLink.net. [For example X_X_X@EarthLink.net.]
| |
| Jürgen Kahrs 2005-01-26, 3:55 pm |
| Gernot Frisch wrote:
> I'm using a cygwin gawk: It uses the '>' as a pipe symbol and writes
> the file "1".
>
> How can I avoid this?
Put the one-liner into a script file and use
"gawk -f file.awk a.txt"
| |
| Chris F.A. Johnson 2005-01-26, 3:55 pm |
| On Wed, 26 Jan 2005 at 14:02 GMT, Gernot Frisch wrote:
> this works:
> cat a.txt|gawk '{if(length($0) ==1) {printf("%s\n", $0);}}'
>
> and this:
> cat a.txt|gawk '{if(length($0) < 1) {printf("%s\n", $0);}}'
>
> gives error:
> gawk: cmd. line:1: {if(length($0) {printf("%s\n", $0);}}
> gawk: cmd. line:1: ^ syntax error
>
> Any idea why?
The script you show is not the script you ran. The error message
shows the script you actually used.
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2005, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
| |
| Kenny McCormack 2005-01-26, 3:55 pm |
| In article <35q4hlF4r01oiU2@individual.net>,
Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
>On Wed, 26 Jan 2005 at 14:02 GMT, Gernot Frisch wrote:
>
> The script you show is not the script you ran. The error message
> shows the script you actually used.
My guess as to what is going on here is that the user is using some version
of GAWK (perhaps it is a Cygwin compiled version, but that is not germane)
with an ordinary Microsoft shell (COMMAND or CMD) and is having quoting
problems. Some people confuse using Cygwin compiled tools with using the
Cygwin (aka, bash, in this context) shell.
So, what happened is that the "< 1" (or is it "> 1"? - conflicting testimony
has been given on that point) is taken out by the shell and not seen by GAWK.
| |
| Ed Morton 2005-01-26, 3:55 pm |
|
Gernot Frisch wrote:
> this works:
> cat a.txt|gawk '{if(length($0) ==1) {printf("%s\n", $0);}}'
>
> and this:
> cat a.txt|gawk '{if(length($0) < 1) {printf("%s\n", $0);}}'
>
> gives error:
> gawk: cmd. line:1: {if(length($0) {printf("%s\n", $0);}}
> gawk: cmd. line:1: ^ syntax error
>
> Any idea why?
Well, yeah - you have an obvious syntax error exactly where the "^" is
pointing. Count the "("s and ")"s before that point.
Ed.
> Thank you.
>
| |
| Bill Marcum 2005-01-31, 3:55 am |
| On Wed, 26 Jan 2005 15:26:48 +0100, Gernot Frisch
<Me@Privacy.net> wrote:
> I'm using a cygwin gawk: It uses the '>' as a pipe symbol and writes
> the file "1".
>
> How can I avoid this?
>
It's the shell, not gawk, that is using the > symbol. Use a cygwin
shell (bash or ksh), not cmd.exe. Or use double quotes.
|
|
|
|
|