awk script fails on solaris 2.4 
Author Message
 awk script fails on solaris 2.4

Quote:

> G'Day,
> the awk script below works as intended on a Linux (Red Hat 4.1) and on a
> SCO 2 box.
> The target machine is a Solaris 2.4.  When I run it on the Solaris box
> I get the following errors -
> awk: syntax error near line 2
> awk: illegal statement near line 2
> awk: syntax error near line 4
> awk: bailing out near line 4

> The synatax seems OK to me and I can't find anything in the Solaris awk
> man pages which says it has a different synatax.  Sorry I could find no
> obvious way of determining the awk that is running on the Solaris box.

> Thanks
> Murray

>  awk '{
>   if (match($0, /BSIC/) == 30){
>    exit 1
>   } else {
>    if (substr($0, 30, 1) == " ") {
>     print substr($0, 0, 29) substr($0, 31)
>    } else {
>     print
>    }
>   }
>  }' $file > temporary_file

> --
> Murray Barton                     Perth, Western Australia

> When a man despoils a work of art we call him a vandal; when he despoils
> a work of nature we call him a developer. - Joseph Wood Krutch

On the sun station, did you try to use 'nawk' in place of 'awk'?

('nawk' stands for "new awk"...   and it should be there too...
Unfortunately, I do not have access to a Sun machine to confirm it.)

This little hint got me out of the jam when I tried to make a awk script
work under Intergraph's CLIX, IBM's AIX, and HP's HP-UX...

Regards, Serge



Sat, 22 Jul 2000 03:00:00 GMT  
 awk script fails on solaris 2.4


Quote:
 writes:

> On the sun station, did you try to use 'nawk' in place of 'awk'?

You could always try looking for /opt/gnu/bin/gawk - never know your luck.

--

  Chris Gray



Sun, 23 Jul 2000 03:00:00 GMT  
 awk script fails on solaris 2.4


% >
% > G'Day,
% > the awk script below works as intended on a Linux (Red Hat 4.1) and on a
% > SCO 2 box.
% > The target machine is a Solaris 2.4.  When I run it on the Solaris box
% > I get the following errors -
[...]

% On the sun station, did you try to use 'nawk' in place of 'awk'?
%
% ('nawk' stands for "new awk"...   and it should be there too...
% Unfortunately, I do not have access to a Sun machine to confirm it.)

In fact, on Solaris (at least up to 2.51), awk is old awk and nawk is new
awk.

For a long time, on Sun machines, troff was C/A/T troff, rather than ditroff,
although they've now left that behind them. Perhaps they will leave old awk
behind them some day, too.
--

Patrick TJ McPhee
East York  Canada



Mon, 24 Jul 2000 03:00:00 GMT  
 awk script fails on solaris 2.4

Quote:

>  awk '{
>   if (match($0, /BSIC/) == 30){
>    exit 1
>   } else {
>    if (substr($0, 30, 1) == " ") {
>     print substr($0, 0, 29) substr($0, 31)
>    } else {
>     print
>    }
>   }
>  }' $file > temporary_file

use back slashes to end the lines. awk (AFAIK) is not a multi line command.

Kuntal Daftary
1.408.527.9789



Mon, 24 Jul 2000 03:00:00 GMT  
 awk script fails on solaris 2.4




%
% >  awk '{
% >   if (match($0, /BSIC/) == 30){
% >    exit 1
% >   } else {
% >    if (substr($0, 30, 1) == " ") {
% >     print substr($0, 0, 29) substr($0, 31)
% >    } else {
% >     print
% >    }
% >   }
% >  }' $file > temporary_file
%
% use back slashes to end the lines. awk (AFAIK) is not a multi line command.

There are circumstances where this is necessary, but not in this case. However,
compare
 nawk '{
   print $1,
         $3
 }'
with
 nawk '{
   print $1
         $3
 }'
and
 nawk '{
   print $1\
         $3
 }'
--

Patrick TJ McPhee
East York  Canada



Tue, 25 Jul 2000 03:00:00 GMT  
 awk script fails on solaris 2.4


: >  awk '{
: >   if (match($0, /BSIC/) == 30){
: >    exit 1
: >   } else {
: >    if (substr($0, 30, 1) == " ") {
: >     print substr($0, 0, 29) substr($0, 31)
: >    } else {
: >     print
: >    }
: >   }
: >  }' $file > temporary_file

Your problem is probably based on the oawk/nawk version problem.
On Sun boxes (and others), try "nawk" rather than "awk".  Generally,
If nawk exists on your machine, use it.  On machines where there is
no nawk, they've renamed it to awk.

[ As an aside, has anyone on any platform encountered problems by replacing
awk with nawk themselves?  ARE there any compatability problems moving
from awk to nawk?  All code I have seen is upwardly compatable. ]


: use back slashes to end the lines. awk (AFAIK) is not a multi line command.

The need for backslashes at the end of awk lines is imposed by the SHELL you
are using (not awk).  csh and its derivatives do not allow multi-line quoted
strings.  This is one reason I switched to a posix shell based on Bourne-shell,
as I write a LOT of in-line awk code.
--



Fri, 28 Jul 2000 03:00:00 GMT  
 awk script fails on solaris 2.4

  awk '{
   if (match($0, /BSIC/) == 30){
    exit 1
   } else {
    if (substr($0, 30, 1) == " ") {
     print substr($0, 0, 29) substr($0, 31)

                      ^---------------------- Isn't 1 the smallest index
in awk?

    } else {
     print
    }
   }
  }' $file > temporary_file



Tue, 01 Aug 2000 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. expect script fails in Solaris 2.4

2. Tcl 8.0b2 test fail - Solaris 2.4/SPARC/Sun compiler

3. Tk4.1 compile on Solaris 2.4 with gcc 2.7.2 failing

4. Tk configure fails on Solaris 2.4

5. Tcl failing on Solaris 2.4

6. Awkcc port for Solaris 2.4 x86

7. 2.5.2 and Solaris 2.4?

8. Can't compile gforth-0.3.0 on Sparc Solaris 2.4

9. Migrating FlagShip from Solaris 2.4 (HyperSparc) to 2.5 on a SparcUltra

10. Migrating FlagShip from Solaris 2.4 (HyperSparc) to 2.5 on a SparcUltra

11. MIT Scheme for Solaris 2.4

12. It's here, gnat 3.01 for Solaris 2.4 x86

 

 
Powered by phpBB® Forum Software