AWK close function 
Author Message
 AWK close function

With this little script I get always the error there are only 10 file sto
open.

awk 'BEGIN {        nJ=0
                    cDatei=sprintf("%s%d", "ya", nJ)
                    print cDatei
                    system(touch cDatei) }
        /^NEU/    { print close(Testatei)
                    nJ++
                    cDatei=sprintf("%s%d", "ya", nJ)
                    print cDatei
                    }
                    { print $0 >> cDatei }
     END {} ' g.txt

I think the close statement did't work. But I have no idea where the mistake
is to find ;-((

I get a textfile and I want it to split it into multiple files with the
beginning from the string "NEU"

Thanks for your answer

Berthold



Thu, 31 Jul 2003 01:58:28 GMT  
 AWK close function

Quote:

> With this little script I get always the error there are only 10 file sto
> open.

> awk 'BEGIN {        nJ=0
>                     cDatei=sprintf("%s%d", "ya", nJ)
>                     print cDatei
>                     system(touch cDatei) }
>         /^NEU/    { print close(Testatei)

shouldn't that be; print close(cDatei) ?

L

Quote:
>                     nJ++
>                     cDatei=sprintf("%s%d", "ya", nJ)
>                     print cDatei
>                     }
>                     { print $0 >> cDatei }
>      END {} ' g.txt

> I think the close statement did't work. But I have no idea where the mistake
> is to find ;-((

> I get a textfile and I want it to split it into multiple files with the
> beginning from the string "NEU"

> Thanks for your answer

> Berthold



Thu, 31 Jul 2003 02:50:22 GMT  
 AWK close function
Thank you for the fast answer,

here are the last lines from the output of the program :

ya10
ya10
ya11
awk: Zu viele Ausgabedateien 10
 Datensatznummer 1441

This is german "awk: Zu viele Ausgabedateien 10" := "awk: to many
outputfiles 10"



Quote:
> On Sat, 10 Feb 2001 18:58:28 +0100, "Berthold Bredenkamp"

> > With this little script I get always the error there are only 10 file
sto
> > open.

> > awk 'BEGIN {        nJ=0
> >                     cDatei=sprintf("%s%d", "ya", nJ)
> >                     print cDatei
> >                     system(touch cDatei) }
> >         /^NEU/    { print close(Testatei)

> shouldn't that be; print close(cDatei) ?

> L

Yes  Laura, you are right, but I made the test with cDatei and it would't
work .

Berthold

- Show quoted text -

Quote:

> >                     nJ++
> >                     cDatei=sprintf("%s%d", "ya", nJ)
> >                     print cDatei
> >                     }
> >                     { print $0 >> cDatei }
> >      END {} ' g.txt

> > I think the close statement did't work. But I have no idea where the
mistake
> > is to find ;-((

> > I get a textfile and I want it to split it into multiple files with the
> > beginning from the string "NEU"

> > Thanks for your answer

> > Berthold



Thu, 31 Jul 2003 03:54:41 GMT  
 AWK close function

Quote:

> With this little script I get always the error there are only 10 file sto
> open.

> awk 'BEGIN {        nJ=0
>                     cDatei=sprintf("%s%d", "ya", nJ)
>                     print cDatei
>                     system(touch cDatei) }
>         /^NEU/    { print close(Testatei)
>                     nJ++
>                     cDatei=sprintf("%s%d", "ya", nJ)
>                     print cDatei
>                     }
>                     { print $0 >> cDatei }
>      END {} ' g.txt

> I think the close statement did't work. But I have no idea where the mistake
> is to find ;-((

Did you try without the print?

I have lots of scripts with similar logic to this one, and they work
fine!

BTW, which version of AWK are you using?



Thu, 31 Jul 2003 04:44:45 GMT  
 AWK close function
It is the awk version for solaris 2.7.

I changed it to gawk 3.0.3 and the script worked fine. So I think the close
statement in the awk version from solaris has a problem. The print statement
shold only tell me if there is a problem with the close . It dosn't worked
without the print befor close.

Thanks for your answer

Berthold



Quote:

> > With this little script I get always the error there are only 10 file
sto
> > open.

> > awk 'BEGIN {        nJ=0
> >                     cDatei=sprintf("%s%d", "ya", nJ)
> >                     print cDatei
> >                     system(touch cDatei) }
> >         /^NEU/    { print close(Testatei)
> >                     nJ++
> >                     cDatei=sprintf("%s%d", "ya", nJ)
> >                     print cDatei
> >                     }
> >                     { print $0 >> cDatei }
> >      END {} ' g.txt

> > I think the close statement did't work. But I have no idea where the
mistake
> > is to find ;-((

> Did you try without the print?

> I have lots of scripts with similar logic to this one, and they work
> fine!

> BTW, which version of AWK are you using?



Thu, 31 Jul 2003 19:22:48 GMT  
 AWK close function

Quote:

> It is the awk version for solaris 2.7.

> I changed it to gawk 3.0.3 and the script worked fine. So I think the close
> statement in the awk version from solaris has a problem. The print statement

The awk in Solaris is so-called 'old' awk, the original version. The original
awk didn't have a close() statement and this is a real limitation because you
can only ever have 10 files open in a single awk program. 'gawk' is a very different
animal from awk, it is one of the modern versions of the language (there are also
mawk, nawk for example) which in true modern fashion add about 2 billion functions,
and get rid of some of the "crippling" limitations (ie: they have a close() function).

Bye,

L

Quote:
> shold only tell me if there is a problem with the close . It dosn't worked
> without the print befor close.

> Thanks for your answer

> Berthold




> > > With this little script I get always the error there are only 10 file
> sto
> > > open.

> > > awk 'BEGIN {        nJ=0
> > >                     cDatei=sprintf("%s%d", "ya", nJ)
> > >                     print cDatei
> > >                     system(touch cDatei) }
> > >         /^NEU/    { print close(Testatei)
> > >                     nJ++
> > >                     cDatei=sprintf("%s%d", "ya", nJ)
> > >                     print cDatei
> > >                     }
> > >                     { print $0 >> cDatei }
> > >      END {} ' g.txt

> > > I think the close statement did't work. But I have no idea where the
> mistake
> > > is to find ;-((

> > Did you try without the print?

> > I have lots of scripts with similar logic to this one, and they work
> > fine!

> > BTW, which version of AWK are you using?



Fri, 01 Aug 2003 00:55:55 GMT  
 AWK close function

Quote:

> The awk in Solaris is so-called 'old' awk, the original version. The original
> awk didn't have a close() statement and this is a real limitation because you
> can only ever have 10 files open in a single awk program. 'gawk' is a very different
> animal from awk, it is one of the modern versions of the language (there are also
> mawk, nawk for example) which in true modern fashion add about 2 billion functions,
> and get rid of some of the "crippling" limitations (ie: they have a close() function).

Hey, what are you doing in here? :-)
Do have any recommendations for a AWK variant/version for
batch programming? It should work in MS-DOS 6.22, and
7.x and also in a DOS box in Windows 4.x, and preferrably
also in NT's so-called DOS emulation.


Fri, 01 Aug 2003 00:06:48 GMT  
 AWK close function

Quote:


> > It is the awk version for solaris 2.7.

> > I changed it to gawk 3.0.3 and the script worked fine. So I think the close
> > statement in the awk version from solaris has a problem. The print statement

> The awk in Solaris is so-called 'old' awk, the original version. The original
> awk didn't have a close() statement and this is a real limitation because you
> can only ever have 10 files open in a single awk program. 'gawk' is a very different
> animal from awk, it is one of the modern versions of the language (there are also
> mawk, nawk for example) which in true modern fashion add about 2 billion functions,
> and get rid of some of the "crippling" limitations (ie: they have a close() function).

I have a time I do not log in a Solaris WS, but I suggest the OP try a
'which nawk' and if it is not there, complain to the admin!

just my .01999...



Fri, 01 Aug 2003 06:03:38 GMT  
 AWK close function
Quote:



[snipped]

Quote:
> Hey, what are you doing in here? :-)
> Do have any recommendations for a AWK variant/version for
> batch programming? It should work in MS-DOS 6.22, and
> 7.x and also in a DOS box in Windows 4.x, and preferrably
> also in NT's so-called DOS emulation.

Whereas the wording seems to be directed to Laura...

If you're willing _really_ sure your script will run even in diskette,
you can try Rob Duff's Pc AWK whose executable is only 47kbytes (and
real mode). You'll find it in Simtel mirrors under textutils as
awk320.zip.

Other possibility is using Michael Brennan's MAWK, which he himself
informs if you need a DOS version you should stick to the 1.2.2 version
(also has a real mode DOS exe). The primary site is
ftp://ftp.whidbey.net/pub/brennan/

If you can run with a bit more of resources I strongly recommend the use
of the gawk port by the DJGPP group (it runs in 'extended' [actually is
called DPMI] 32 bit mode DOS) you'll find it in Simtel mirrors under
gnu/djgpp/v2gnu, present port is ver 3.0.6.

HTH

Cesar



Fri, 01 Aug 2003 06:11:49 GMT  
 AWK close function

Quote:



> [snipped]

> > Hey, what are you doing in here? :-)
> > Do have any recommendations for a AWK variant/version for
> > batch programming? It should work in MS-DOS 6.22, and
> > 7.x and also in a DOS box in Windows 4.x, and preferrably
> > also in NT's so-called DOS emulation.

> Whereas the wording seems to be directed to Laura...

> If you're willing _really_ sure your script will run even in diskette,
> you can try Rob Duff's Pc AWK whose executable is only 47kbytes (and
> real mode). You'll find it in Simtel mirrors under textutils as
> awk320.zip.

> Other possibility is using Michael Brennan's MAWK, which he himself
> informs if you need a DOS version you should stick to the 1.2.2 version
> (also has a real mode DOS exe). The primary site is
> ftp://ftp.whidbey.net/pub/brennan/

> If you can run with a bit more of resources I strongly recommend the use
> of the gawk port by the DJGPP group (it runs in 'extended' [actually is
> called DPMI] 32 bit mode DOS) you'll find it in Simtel mirrors under
> gnu/djgpp/v2gnu, present port is ver 3.0.6.

Thanks, I'll check out Pc AWK and MAWK. I use MS-DOS 6.22 and
WfW 3.11, but I also need my batches to run on the other
platforms. If I use Pc AWK or MAWK will my batches be portable
to the other platforms as well as run on my own computer?


Fri, 01 Aug 2003 03:59:40 GMT  
 AWK close function
On Solaris the trick is to ensure that you have /usr/xpg4/bin in your path
before /usr/bin - then you get the POSIX compliant awk rather than the
unbelievably ancient one in /usr/bin.  IMO the POSIX compliant one is better
than the "nawk" on Solaris.  Even better forget the Solaris implementation
completely and use gawk!

HTH
--



Opinions expressed are my own and not necessarily those of my

Quote:
> It is the awk version for solaris 2.7.

> I changed it to gawk 3.0.3 and the script worked fine. So I think the
close
> statement in the awk version from solaris has a problem. The print
statement
> shold only tell me if there is a problem with the close . It dosn't worked
> without the print befor close.

> Thanks for your answer

> Berthold




> > > With this little script I get always the error there are only 10 file
> sto
> > > open.

> > > awk 'BEGIN {        nJ=0
> > >                     cDatei=sprintf("%s%d", "ya", nJ)
> > >                     print cDatei
> > >                     system(touch cDatei) }
> > >         /^NEU/    { print close(Testatei)
> > >                     nJ++
> > >                     cDatei=sprintf("%s%d", "ya", nJ)
> > >                     print cDatei
> > >                     }
> > >                     { print $0 >> cDatei }
> > >      END {} ' g.txt

> > > I think the close statement did't work. But I have no idea where the
> mistake
> > > is to find ;-((

> > Did you try without the print?

> > I have lots of scripts with similar logic to this one, and they work
> > fine!

> > BTW, which version of AWK are you using?



Fri, 01 Aug 2003 05:53:23 GMT  
 AWK close function

Quote:

> On Solaris the trick is to ensure that you have /usr/xpg4/bin in your path
> before /usr/bin - then you get the POSIX compliant awk rather than the

Thanks for the tip! May need to work in Suns any day...

Quote:
> unbelievably ancient one in /usr/bin.  IMO the POSIX compliant one is better
> than the "nawk" on Solaris.  Even better forget the Solaris implementation
> completely and use gawk!

If the sysadmin at the installation allows you to install executables at
all. . . but I second your preference as well.

Cesar



Fri, 01 Aug 2003 07:30:50 GMT  
 AWK close function

Quote:

[snipped]

> Thanks, I'll check out Pc AWK and MAWK. I use MS-DOS 6.22 and
> WfW 3.11, but I also need my batches to run on the other
> platforms. If I use Pc AWK or MAWK will my batches be portable
> to the other platforms as well as run on my own computer?

I understand that what you call 'your batches' will be the scripts
you'll start to write.

These two implementations are, from what I recall from my experience,
near enough to the modern language (a.k.a. New AWK, fun call something
'new' with 12+ years in computer technology!), that except for the
glitch that started this thread, you'll probably are on the safe side.

However, remember when transferring the scripts to other plattforms,
you'll need to be careful with the CR LF (DOS) versus LF (U**x) and
perhaps something similar in Macs (anyone in the Group has an
authoritave info on this? I've been told Macs use CRs as EOL marker).

OTOH, if you mean the DOS batch files (.BAT) plus the scripts, you'll
need to check how to port them to other shell's languages.

HTH

Cesar



Fri, 01 Aug 2003 07:38:36 GMT  
 AWK close function

Quote:


> [snipped]

> > Thanks, I'll check out Pc AWK and MAWK. I use MS-DOS 6.22 and
> > WfW 3.11, but I also need my batches to run on the other
> > platforms. If I use Pc AWK or MAWK will my batches be portable
> > to the other platforms as well as run on my own computer?

> I understand that what you call 'your batches' will be the scripts
> you'll start to write.

> These two implementations are, from what I recall from my experience,
> near enough to the modern language (a.k.a. New AWK, fun call something
> 'new' with 12+ years in computer technology!), that except for the
> glitch that started this thread, you'll probably are on the safe side.

> However, remember when transferring the scripts to other plattforms,
> you'll need to be careful with the CR LF (DOS) versus LF (U**x) and
> perhaps something similar in Macs (anyone in the Group has an
> authoritave info on this? I've been told Macs use CRs as EOL marker).

> OTOH, if you mean the DOS batch files (.BAT) plus the scripts, you'll
> need to check how to port them to other shell's languages.

I have been doing DOS batch (.bat) file programming for over five
years now in MS-DOS 6.22. I discovered that DOS 7 is seriously
broken. This makes 'pure' batch programming in DOS 7.x versions
undesireable (as I am sure was M$'s intention). In order to do
batch programming in DOS 7.x, I need a robust and portable language
that I can combine with batch and continue my work on these platforms.
Ultimately (sometime in the future), I want to move to Unix/Linux.


Fri, 01 Aug 2003 13:52:35 GMT  
 AWK close function
[snipped]

Quote:

> I have been doing DOS batch (.bat) file programming for over five
> years now in MS-DOS 6.22. I discovered that DOS 7 is seriously
> broken. This makes 'pure' batch programming in DOS 7.x versions
> undesireable (as I am sure was M$'s intention). In order to do
> batch programming in DOS 7.x, I need a robust and portable language
> that I can combine with batch and continue my work on these platforms.
> Ultimately (sometime in the future), I want to move to Unix/Linux.

For the purposes intended, AWK fulfills your requirements about
robustness and portability (in fact it is a mature language POSIX
standarized).

However it will not substitute batch programming. If you have this
possibility, look for shareware/freeware alternate shells to use for
this need. There is even a bash port, which except for the most arcane
system dependencies can be used to create portable shell scripts.

In the long run, you may consider to hava a hand the standard toolset of
shell utilities generally available in Unix. A particular enlightening
document you can refer to is the "Opening the software toolbox" node in
the 'textutils' info file (also recommended is 'shellutils'). If you
decide they are the way you want go, they're free software (FSF).

HTH

Cesar



Sat, 02 Aug 2003 04:13:12 GMT  
 
 [ 15 post ] 

 Relevant Pages 

1. Application stops functioning when window is closed

2. Using search tool on function or control pallette causes Labview to close

3. how to disable mwm's close function

4. Problem with close function in routine using pipe

5. APLish AWK functions

6. Inverse trigonometric functions in awk

7. return multiple values from an awk function?

8. Format functions in AWK

9. Lookup function in awk - answer

10. Including awk (mawk) functions in a script

11. can AWK read function from input file?

12. Unescape function in Awk

 

 
Powered by phpBB® Forum Software