newline in gawk program file 
Author Message
 newline in gawk program file

If I create a file containing only:

{print}

I get "Invalid char '

It seems to be the newline.

I can run this from the cmd line

gawk '{print}' my-file

no problem.

This must be something incredibly obvious but I can't seem to work it
out.  I've downloaded & build 3.0.5 of gawk & still get the problem.

This is redhat linux - I can do this okay at work on win32 gawk.

Any ideas?
Thanks,Abe

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Mon, 16 Dec 2002 03:00:00 GMT  
 newline in gawk program file

Quote:

> If I create a file containing only: {print} I get "Invalid char ' It
> seems to be the newline.  I can run this from the cmd line gawk
> '{print}' my-file no problem.  This must be something incredibly
> obvious but I can't seem to work it out.  I've downloaded & build
> 3.0.5 of gawk & still get the problem.  This is redhat linux - I can
> do this okay at work on win32 gawk.

Control-M (ASCII 13 or CR) is OK when directly preceding a Control-J
(ASCII 10 or LF) character if Gawk is running under MS-DOS, but in
most other circumstances it's a meaningless character out of place
which will give an errormessage (unless carefully quoted or escaped as
part of a string or regular expression).  This ultimately has to do
with MS-DOS following the intent of early ASCII standards in its
newline conventions, while Unix went off on its own idiosyncratic
path, but the immediate rememdy is to remove the ^M's from the Unix
file; here's a quick script to do so:

tr -d '\015' < $1  > $2

--%!PS
10 10 scale/M{rmoveto}def/R{rlineto}def 12 45 moveto 0 5 R 4 -1 M 5.5 0 R
currentpoint 3 sub 3 90 0 arcn 0 -6 R 7.54 10.28 M 2.7067 -9.28 R -5.6333
2 setlinewidth 0 R 9.8867 8 M 7 0 R 0 -9 R -6 4 M 0 -4 R stroke showpage



Mon, 16 Dec 2002 03:00:00 GMT  
 newline in gawk program file
Thanks for your answer.
Actually - it doesn't seem to be this.  I did have a grub around in the
file with od to see if it was cr-lf or something.  I generated the file
with vi and also tried emacs - it's just an ordinary unix text file
with lf only.
I even tried inserting ctrl-m to see if it wanted ms-dos format on
linux - it doesn't seem to.
I'm absolutely stumped about this - I don't think there could be such a
glaring problem, so I must be missing something.



Quote:


> > If I create a file containing only: {print} I get "Invalid char ' It
> > seems to be the newline.  I can run this from the cmd line gawk
> > '{print}' my-file no problem.  This must be something incredibly
> > obvious but I can't seem to work it out.  I've downloaded & build
> > 3.0.5 of gawk & still get the problem.  This is redhat linux - I can
> > do this okay at work on win32 gawk.

> Control-M (ASCII 13 or CR) is OK when directly preceding a Control-J
> (ASCII 10 or LF) character if Gawk is running under MS-DOS, but in
> most other circumstances it's a meaningless character out of place
> which will give an errormessage (unless carefully quoted or escaped as
> part of a string or regular expression).  This ultimately has to do
> with MS-DOS following the intent of early ASCII standards in its
> newline conventions, while Unix went off on its own idiosyncratic
> path, but the immediate rememdy is to remove the ^M's from the Unix
> file; here's a quick script to do so:

> tr -d '\015' < $1  > $2

> --%!PS
> 10 10 scale/M{rmoveto}def/R{rlineto}def 12 45 moveto 0 5 R 4 -1 M 5.5
0 R
> currentpoint 3 sub 3 90 0 arcn 0 -6 R 7.54 10.28 M 2.7067 -9.28 R -
5.6333
> 2 setlinewidth 0 R 9.8867 8 M 7 0 R 0 -9 R -6 4 M 0 -4 R stroke
showpage


Sent via Deja.com http://www.deja.com/
Before you buy.


Tue, 17 Dec 2002 03:00:00 GMT  
 newline in gawk program file
Henry - you are quite right - there WAS a cr.  I looked again & found it
with od - dunno what I was thinking of earlier.

I realised this was a file I'd brought across from dos - vi isn't
bothered about the cr.

Thanks for your time and help!



Quote:


> > If I create a file containing only: {print} I get "Invalid char ' It
> > seems to be the newline.  I can run this from the cmd line gawk
> > '{print}' my-file no problem.  This must be something incredibly
> > obvious but I can't seem to work it out.  I've downloaded & build
> > 3.0.5 of gawk & still get the problem.  This is redhat linux - I can
> > do this okay at work on win32 gawk.

> Control-M (ASCII 13 or CR) is OK when directly preceding a Control-J
> (ASCII 10 or LF) character if Gawk is running under MS-DOS, but in
> most other circumstances it's a meaningless character out of place
> which will give an errormessage (unless carefully quoted or escaped as
> part of a string or regular expression).  This ultimately has to do
> with MS-DOS following the intent of early ASCII standards in its
> newline conventions, while Unix went off on its own idiosyncratic
> path, but the immediate rememdy is to remove the ^M's from the Unix
> file; here's a quick script to do so:

> tr -d '\015' < $1  > $2

> --%!PS
> 10 10 scale/M{rmoveto}def/R{rlineto}def 12 45 moveto 0 5 R 4 -1 M 5.5
0 R
> currentpoint 3 sub 3 90 0 arcn 0 -6 R 7.54 10.28 M 2.7067 -9.28 R
-5.6333
> 2 setlinewidth 0 R 9.8867 8 M 7 0 R 0 -9 R -6 4 M 0 -4 R stroke
showpage


Sent via Deja.com http://www.deja.com/
Before you buy.


Wed, 18 Dec 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. GAWK newlines in xxDOS/Windows

2. PEP 259: Omit printing newline after newline

3. PEP 259: Omit printing newline after newline

4. Gawk for win32 slower than Gawk for Dos_32?

5. Gawk bug, gawk won't nawk.

6. gawk 3.0.95, beta for gawk 3.1.0, now available

7. How to remove newlines in text file

8. deleting newline from last line in file

9. Remove trailing newlines from file

10. drop every newline in file and then ...

11. Behavior of newline character in ANS Forth, using WRITE-FILE

12. ascii & newlines in unformatted file

 

 
Powered by phpBB® Forum Software