read two files 
Author Message
 read two files

Hi,

I am new in the awk tool, now I am having a problem to let the awk
to read two text files in the same.  What I need to do is to combine
some particular columns of each file to form a new file.  like

fileA                        fileB

col11   col21            a11    b11
col12   col22            a12    b22
col12   col23            a13    b23

form fileC
col11b11
col22b22
col23b23

thanks for your help.



Sat, 31 Mar 2001 03:00:00 GMT  
 read two files



Quote:
> Hi,

> I am new in the awk tool, now I am having a problem to let the awk
> to read two text files in the same.  What I need to do is to combine
> some particular columns of each file to form a new file.  like

> fileA                        fileB

> col11   col21            a11    b11
> col12   col22            a12    b22
> col12   col23            a13    b23

> form fileC
> col11b11
> col22b22
> col23b23

> thanks for your help.

try
getline < "fileB"
this reads the next record from file fileB into $0 and splits it into fields


Sat, 31 Mar 2001 03:00:00 GMT  
 read two files

: Hi,
:
: I am new in the awk tool, now I am having a problem to let the awk
: to read two text files in the same.  What I need to do is to combine
: some particular columns of each file to form a new file.  like
:
: fileA                        fileB
:
: col11   col21            a11    b11
: col12   col22            a12    b22
: col12   col23            a13    b23
:
: form fileC
: col11b11
: col22b22
: col23b23
:  
: thanks for your help.
:

You may consider it cheating, but
$ pr -m -t fileA fileB | awk '{print $1 $4}'
works very well for me.  Otherwise try something like
$ awk '{if(file==FILENAME){++n} else {++m;n=1;file=FILENAME};if (m==0){row[n]=$1}else{row[n]=row[n] $2}} END {for(i=1;i<=n;i++)print row[i]}' fileA fileB

Personally I find the first one easier to understand. ;>

--

  Chris Gray



Sat, 31 Mar 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. reading two files and comparing them

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

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

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

5. reading from two files, how?

6. NEWBIE TIP: Reading a file two different ways...from ENGSOL

7. reading two separate files

8. how to compare two columns in two files?

9. Two files, two linking keys

10. Merge selected columns from two different files into another file

11. merging 2 columns from two files in one file

12. one file unit accessing two different files?

 

 
Powered by phpBB® Forum Software