Write to 2 file from pipe without using temp file 
Author Message
 Write to 2 file from pipe without using temp file

I have a script which generate the following outputs :-

1123000  23445  883450  7780
2250000  11793  23356  8810
                     "
                     "

The script is something like :-

script1 | script2 | script3

Is it possible to pipe to another script to write the first 2 columns to
file1
and the last 2 columns to file2 without using a temp file ?

Y W Wong



Mon, 22 Oct 2001 03:00:00 GMT  
 Write to 2 file from pipe without using temp file
Quote:

> I have a script which generate the following outputs :-

> 1123000  23445  883450  7780
> 2250000  11793  23356  8810
>                      "
>                      "

> The script is something like :-

> script1 | script2 | script3

> Is it possible to pipe to another script to write the first 2 columns to
> file1
> and the last 2 columns to file2 without using a temp file ?

> Y W Wong

... | while read A B C D
do
        echo "$A $B" >> file1
        echo "$C $D" >> file2
done

If you have to preserve the spaces use line and cut.

HTH, Ralf.
--

- Intraplan Consult Gmbh  Orleansplatz 5a  81667 Muenchen  +49 89 45911-0 -

"Mr. Worf, scan that ship." "Aye Captain. 300 dpi?"



Mon, 22 Oct 2001 03:00:00 GMT  
 Write to 2 file from pipe without using temp file
Quote:

> I have a script which generate the following outputs :-

> 1123000  23445  883450  7780
> 2250000  11793  23356  8810
>                      "
>                      "

> The script is something like :-

> script1 | script2 | script3

> Is it possible to pipe to another script to write the first 2 columns to
> file1
> and the last 2 columns to file2 without using a temp file ?

Yes. "man awk".


Mon, 22 Oct 2001 03:00:00 GMT  
 Write to 2 file from pipe without using temp file


Quote:
>I have a script which generate the following outputs :-

>1123000  23445  883450  7780
>2250000  11793  23356  8810
>                     "
>                     "

>The script is something like :-

>script1 | script2 | script3

>Is it possible to pipe to another script to write the first 2 columns
>to file1 and the last 2 columns to file2 without using a temp file ?

(I assume that by "file1" and "file2", you mean "script2" and "script3",
 since otherwise the question makes no sense)

Not directly, i.e., in the shell.  You could do the following in AWK:

        # This is "script1"
        {
        print $1,$2 | "script2"
        print $3,$4 | "script3"
        }



Mon, 22 Oct 2001 03:00:00 GMT  
 Write to 2 file from pipe without using temp file


Quote:
>I have a script which generate the following outputs :-

>1123000  23445  883450  7780
>2250000  11793  23356  8810
>                     "
>                     "

>The script is something like :-

>script1 | script2 | script3

>Is it possible to pipe to another script to write the first 2 columns to
>file1
>and the last 2 columns to file2 without using a temp file ?

pipe it to:

awk '{print $1,$2 > "file1"; print $3,$4 > "file2"}'

Read the man page for awk.

man awk

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Mon, 22 Oct 2001 03:00:00 GMT  
 Write to 2 file from pipe without using temp file


   >The script is something like :-
   >script1 | script2 | script3
   >Is it possible to pipe to another script to write the first 2
   >columns to file1
   >and the last 2 columns to file2 without using a temp file ?
   >Y W Wong
awk '{print $1,$2>file1;print $3,$4>file2}'

Net-Tamer V 1.08X - Test Drive



Mon, 22 Oct 2001 03:00:00 GMT  
 Write to 2 file from pipe without using temp file

Quote:

>> I have a script which generate the following outputs :-

>> 1123000  23445  883450  7780
>> 2250000  11793  23356  8810

>> The script is something like :-

>> script1 | script2 | script3

>> Is it possible to pipe to another script to write the first 2 columns to
>> file1
>> and the last 2 columns to file2 without using a temp file ?

>Yes. "man awk".

I don't think that awk doesn't use temp files.
--
Michael Wang
http://www.mindspring.com/~mwang


Tue, 23 Oct 2001 03:00:00 GMT  
 Write to 2 file from pipe without using temp file

Quote:



>>> I have a script which generate the following outputs :-

>>> 1123000  23445  883450  7780
>>> 2250000  11793  23356  8810

>>> The script is something like :-

>>> script1 | script2 | script3

>>> Is it possible to pipe to another script to write the first 2 columns to
>>> file1
>>> and the last 2 columns to file2 without using a temp file ?

>>Yes. "man awk".

>I don't think that awk doesn't use temp files.

That's alright, you're allowed to be wrong. :-)  

AFAIK, awk, and particularly gawk, does not use temporary files, but
uses memory to store things while working.  At least that's my
understanding of it on a Unix system.  How it may be implemented
on other systems, I don't know.

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Tue, 23 Oct 2001 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. files, temp files, and file-like objects

2. Writing two equal files without creating two files in dct

3. help me to execute my file without using wish (menu file, command source)

4. How do I replace a file using Write Characters to file.vi

5. Writing perl script to pipe to 2 files from tail -f command

6. BOSS without writing to files

7. Writing binary data to a file without carriage returns every 512 bytes

8. help with writing to a sequential file without suppress all my spaces

9. Writing seq files without crlf

10. in-file search/replace question without using mv or cp

11. changing file directory at runtime without using a variable in prop:name

12. Using TBrowse without a DBF file

 

 
Powered by phpBB® Forum Software