how to close file, how much command 
Author Message
 how to close file, how much command

How do you close files in awk?
That is, HOW MUCH command is needed between the quotes in the close()
command?

I am getting error too many files (error 24)
on SCO UNIX OpenServer,
probably nawk.

I read the pages in Arnold Robbins book, and the original Aho,
Kernighan, Weinbeger book.
Quite cryptic, no?

I am bundling/unbundling, like a flat file.

I clipped my session, see below.
-----------
$ awk -F"\t" '

Quote:
> { fout = "/tmp/kim." $1
> print $2 >> fout
> close("print $2 >> fout")
> }' kim..

awk: can't open file /tmp/kim.OE.CONTROL.M2: Too many open files (error
24)
 input record number 2195, file kim..
 source line 4 of program <<
{ fout = "/tmp/kim. ... >>
$
----------
The data file is formatted like flat file, or bundled file.
Where filename precedes 10-20 line of data.
There are 700+ filenames, and therefore maybe (700x20=)14,000 lines.
---------
file1 <tab> line1
file1 <tab> line2
file1 <tab> line3
file2 <tab> line1
file2 <tab> line2
file3 <tab> line1
...
filen <tab> line1
filen <tab> line2
filen <tab> linen
---------
Goal is to unbundle = to strip the prefix, and use prefix as filename to
contain lines.

p.s.- comp.lang.awk is the BEST!
I can do for loops now, thanks to you guys! (Curly Braces up front,
wuddya know?)
-----------
-Kim Goldsworhty



Wed, 24 Oct 2001 03:00:00 GMT  
 how to close file, how much command
On Sat, 08 May 1999 12:49:44 -0700, Kim Goldsworthy

Quote:

>How do you close files in awk?
>That is, HOW MUCH command is needed between the quotes in the close()
>command?

>I am getting error too many files (error 24)
>on SCO UNIX OpenServer,
>probably nawk.

>I read the pages in Arnold Robbins book, and the original Aho,
>Kernighan, Weinbeger book.
>Quite cryptic, no?

>I am bundling/unbundling, like a flat file.

>I clipped my session, see below.
>-----------
>$ awk -F"\t" '
>> { fout = "/tmp/kim." $1
>> print $2 >> fout
>> close("print $2 >> fout")

close(fout)

--
Steve



Wed, 24 Oct 2001 03:00:00 GMT  
 how to close file, how much command

Quote:

>How do you close files in awk?
>That is, HOW MUCH command is needed between the quotes in the close()
>command?

. . .

Quote:
>I read the pages in Arnold Robbins book, and the original Aho,
>Kernighan, Weinbeger book.
>Quite cryptic, no?

No. I haven't read Robbins's book, but the AKW book is IMHO one of the finest
programming books ever written.
. . .

Quote:
>$ awk -F"\t" '
>> { fout = "/tmp/kim." $1
>> print $2 >> fout
>> close("print $2 >> fout")
>> }' kim..

Should be  close(fout)


Wed, 24 Oct 2001 03:00:00 GMT  
 how to close file, how much command

Quote:

> >I read the pages in Arnold Robbins book, and the original Aho,
> >Kernighan, Weinbeger book.
> >Quite cryptic, no?

> No. I haven't read Robbins's book, but the AKW book is IMHO one of the finest
> programming books ever written.

I have Robbins' book on my shelf. Is it cryptic ? No, I think it is
as readable as a book about a scripting language can be. What I like
most about Robbins' book is:

  1. It is free. You get it with the GAWK distribution.
  2. The enclosed Reference Card is so useful that I wear one
     constantly around with me.

But you are right about the AWK book by Aho et al.
It is a small book (210 pages) and if I had to choose one book,
I would take this.

________________________________________________________________________

Juergen Kahrs                                       Tel.  0421  249 666
Millstaetter Strasse 15                             Tel.  0421  457 2819
D 28359 Bremen                                      Fax   0421  457 3578
____________ http://home.t-online.de/home/Juergen.Kahrs/ _______________



Thu, 25 Oct 2001 03:00:00 GMT  
 how to close file, how much command


% How do you close files in awk?
% That is, HOW MUCH command is needed between the quotes in the close()
% command?

[...]

% > print $2 >> fout
% > close("print $2 >> fout")

You're getting confused between printing to a file and printing to
a pipeline. If you redirect output into a command pipe-line, you need
to pass the entire command, including arguments, to close():
 print $2 | "sort -n"
 close("sort -n")
and spaces count, so this isn't the same as
 print $2 | "sort  -n"
 close("sort -n")

The easiest way to deal with this is to put the command in a variable:
 sort = "sort -n"
 print $2 | sort
 close(sort)

In your case, you're not doing this; you're printing to a file. All you
need to pass to close is the name of the file:
 fout = "myfile.txt"
 print $2 >> fout
 close(fout)

In neither case do you pass the actual awk statement to close.

I don't think the books you mention are cryptic, although some of the
concepts aren't immediately obvious, and that can lead to difficulties.
--

Patrick TJ McPhee
East York  Canada



Thu, 25 Oct 2001 03:00:00 GMT  
 how to close file, how much command
<snip>

Quote:
> I read the pages in Arnold Robbins book, and the original Aho,
> Kernighan, Weinbeger book.
> Quite cryptic, no?

<snip>
> -Kim Goldsworhty

The O'Reilly book "SED & AWK 2nd." by Dogherty and Robbins is very good.

Also there are some very good examples in Arnold Robbins html-based
book, for example awk implementations of getopt and wc.

Peter
--


Opinions expressed are my own and not necessarily those of my employer.



Sat, 27 Oct 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Device file not closing on close command

2. Closed file not really closed

3. Save Report to File.vi closing file problems

4. MF Cobol File Locks,ATomic File Close/Delt

5. Getting a Dos window close when using the RUN command

6. How can I automatically close the DOS Window after executing the RUN command

7. Close command window from Rexx/NT

8. Fujitsu and the close command ?

9. Tkinter Close Command

10. Problem with CLOSE command

11. closing command pipelines on Windows

12. invoke command before closing Application

 

 
Powered by phpBB® Forum Software