two files one script 
Author Message
 two files one script

hi out there,
i got two files (fields seperated with blanks). i want to chance or
overwrite some fields from the second file with the some fields from the
first file.
how can i manage the fields of both files.

file 1:       file 2:                  output:

1 2 3 4    a b c d               1 2 g 4
5 6 7 8    e f g h                 5 6 7 8

for example i want to overwrite file1:3 with file2:g.
thanks for help



Sun, 04 Nov 2001 03:00:00 GMT  
 two files one script
Hi there,

what I usually do is:
{if(FILENAME=="file1"){ fill arr[$1] and so on;next}}
{handle second file here, using the arr[]'s with the fields froms
file1},
but I don't see how the fields are logically connected in your example,
please specify your prob a bit more.
Greetings
Norbert

Reinhold Just schrieb:

Quote:

> hi out there,
> i got two files (fields seperated with blanks). i want to chance or
> overwrite some fields from the second file with the some fields from the
> first file.
> how can i manage the fields of both files.

> file 1:       file 2:                  output:

> 1 2 3 4    a b c d               1 2 g 4
> 5 6 7 8    e f g h                 5 6 7 8

> for example i want to overwrite file1:3 with file2:g.
> thanks for help



Sun, 04 Nov 2001 03:00:00 GMT  
 two files one script

Quote:

> i got two files (fields seperated with blanks). i want to chance or
> overwrite some fields from the second file with the some fields from the
> first file.
> how can i manage the fields of both files.

You can eat one whole file into an array, e.g. in the BEGIN rule:

BEGIN \
{
  while((getline <OneFile) > 0)
  {
    Array[++MyFNR] = $0
    # or, if you're only interested in one/some field(s) of the file,
    # remember only these fields:
    # Field1[++MyFNR] = $1
    # Field2[  MyFNR] = $2
  }
  close(OneFile)

Quote:
}

Of course you have to set the OneFile variable before using it,
e.g. with the `-v' option of gawk.

Afterwards you read through your other file in the "main loop" and
lookup things from the Array.

If you don't need to lookup things in your whole OneFile, you can read
OneFile line by line inside your mainloop, just at the moment you need
these lines:

{
  DoWhatYouWantWith($0)
  getline <OneFile
  DoWhatYouWantWithYourNew($0)

Quote:
}

You might want to read the manual sections about `getline'.

Regards...
        Michael



Sun, 04 Nov 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. merging 2 columns from two files in one file

2. how to read one file, print to two files

3. one file unit accessing two different files?

4. How to replace one or two words with one word with one line of awk code

5. How to bind one script to two events?

6. Can _One_ Tcl/Tk script run _Two_ displays?

7. read two sets of data from two spread sheet files to two arrays problem

8. Reports with One Parent and Two Child files(multiple records eacy)

9. ABC Browse - Two related files in one window

10. Two data files in one browse?

11. Two browse boxes with same file on one window

12. Two dictionaries sharing one file

 

 
Powered by phpBB® Forum Software