Combine multiple columns from multiple files

Hi there,

I was wondering if someone can help me with this.

I am trying the combine multiple columns from multiple files into one file.

Example file 1:

c0t0d0 c0t2d0 # hostname vgname
c0t0d1 c0t2d1 # hostname vgname
c0t0d2 c0t2d2 # hostname vgname
c0t1d0 c0t3d0 # hostname vgname1
c0t1d3 c0t3d3 # hostname vgname1

Example file 2:

c0t0d0 c0t4d0 # hostname1 vgname
c0t0d1 c0t4d1 # hostname1 vgname
c0t0d2 c0t4d2 # hostname1 vgname
c0t1d0 c0t6d0 # hostname1 vgname1
c0t1d3 c0t6d3 # hostname1 vgname1

Preffered Output:

c0t2d0 c0t4d0 # hostname vgname
c0t2d1 c0t4d1 # hostname vgname
c0t2d2 c0t4d2 # hostname vgname
c0t3d0 c0t6d0 # hostname vgname1
c0t3d3 c0t6d3 # hostname vgname1

The only constant variable in this all is the vgname.
I've searched the forum simular posts, but when trying i don't get the desired output. The biggest problem is the formating of the output file.

Can someone help me with this.

Running HP-UX B.11.23 ia64

I have just tried the join command. Not what i need right now.

I have also tried this one:

cat file1 | awk {'print $2'} > file3
cat file2 | awk {'print $1, $3, $4, $5'} > file4
paste file3 file4

There most be an easier way. Also with this option I have to check every ctd number in every line is are part of the same VG.

Your followup message includes only: "Anyone? "

You did not provide the rules for how to combine the two files into one file.
It appears that you are taking the 2nd column of file one, making it the first column of your output; and taking the 2nd column to end of file two, making it columns two to end of your output.

Correct?

Yes, that's correct.

So in the example above my output will be the following:

c0t2d0 c0t0d0 # hostname1 vgname
c0t2d1 c0t0d1 # hostname1 vgname
c0t2d2 c0t0d2 # hostname1 vgname
c0t3d0 c0t1d0 # hostname1 vgname1
c0t3d3 c0t1d3 # hostname1 vgname1

> cat file87
c0t0d0 c0t2d0 # hostname vgname
c0t0d1 c0t2d1 # hostname vgname
c0t0d2 c0t2d2 # hostname vgname
c0t1d0 c0t3d0 # hostname vgname1
c0t1d3 c0t3d3 # hostname vgname1
> cat file88
c0t0d0 c0t4d0 # hostname1 vgname
c0t0d1 c0t4d1 # hostname1 vgname
c0t0d2 c0t4d2 # hostname1 vgname
c0t1d0 c0t6d0 # hostname1 vgname1
c0t1d3 c0t6d3 # hostname1 vgname1

> cat f87_88
awk ' FILENAME=="file87" { dat[$1]=$2}
      FILENAME=="file88" { 
        if(FNR > 0)
        { print dat[$1]" "$2" "$3" "$4" "$5}
      
      } ' file87 file88
       
> f87_88
c0t2d0 c0t4d0 # hostname1 vgname
c0t2d1 c0t4d1 # hostname1 vgname
c0t2d2 c0t4d2 # hostname1 vgname
c0t3d0 c0t6d0 # hostname1 vgname1
c0t3d3 c0t6d3 # hostname1 vgname1

He, it works.

Oke, say i want the files to be user provided, because not all files have the same name. Like this:

> f87_88 file87 file88

That means that the option FILENAME== is user provided.

Second, I need to be sure the devices in the file both correspond the same VG. So that if I run the script, I don't have to check the devices afterwards.

Regards

Edit:
My awk experience is very basic.