Replace column with column from another file

Hello,

I am trying to replace the column in file1 with the column from file2. The two files will have the same amount of rows. Each row will correspond with the same row in the other file.

File1

 
                                            "Replace this column"
500     13-APR-2011 09:00:00 PM       DPDP     00-00-0001234567      Stuff (500)        Stuff 500
500     13-APR-2011 09:00:00 PM       DPDP     00-00-0008912345      Things (625)       Things 625 

File2

 
00001234567 
00008912345

awk is preferred.

Thanks.

Try:

awk 'NR==FNR{a[NR]=$0;next}{$6=a[FNR]}1' File2 File1

Thanks. tried this and it didn't replace the $6 field. It just added the column to the begninning of each line.

That is weird, because for your input files my code is working fine...

[root@linux ff]# cat File1
500 13-APR-2011 09:00:00 PM DPDP 00-00-0001234567 Stuff (500) Stuff 500
500 13-APR-2011 09:00:00 PM DPDP 00-00-0008912345 Things (625) Things 625
[root@linux ff]# cat File2
00001234567
00008912345
[root@linux ff]# awk 'NR==FNR{a[NR]=$0;next}{$6=a[FNR]}1' File2 File1
500 13-APR-2011 09:00:00 PM DPDP 00001234567  Stuff (500) Stuff 500
500 13-APR-2011 09:00:00 PM DPDP 00008912345 Things (625) Things 625

That is weird. I tried three times and got the same result. Added it to the beginning...

What could be causing that?

Does your input files look exactly like those in first post? What operating system are you using?

Yeah, my output files look exactly like that.

We are on HPUX 11.23.

Do you have Perl there?

perl -pe 'BEGIN{open I,"File2";chomp(@a=<I>);}s/((\S+\s+){5})(\S+)(\s+)/\1$a[$.-1]\4/' File1

Nice. That worked.

Is there any way you could explain this to me or point me in the right direction where I can look at docs for this?

Thanks a lot. Really appreciate your help.

Learning this will come in very handy. I'll take a look at the O'Reilly.

Thanks again.

Try this with your "Hp-ux awk"

awk 'NR==FNR{a[NR]=$0}{$6=a[FNR]}NR!=FNR' File2 File1