cancel
Showing results for 
Search instead for 
Did you mean: 

Basic HPUX Question

Mark Hess
Occasional Contributor

Basic HPUX Question

I'm a HPUX rookie and have what I believe is probably a simple question. I'm having trouble combining columns of two text files. For example I have a file XYZ with columns A & B. I have another file ABC with columns A & C. I want to add column C to file XYZ so then file XYZ has columns A, B & C. I think either
the functions "sort" or "join" can do this, but can't figure out how.

Thanks in advance to anyone who can answer this question or lead me in the right direction.

Mark
6 REPLIES
James R. Ferguson
Acclaimed Contributor

Re: Basic HPUX Question

Hi Mark:

See 'paste'.

Regards!

...JRF...
Sandip Ghosh
Honored Contributor

Re: Basic HPUX Question

Hi Mark ,

take out one coloumn from the file ABC and "paste" the file ABC to XYZ.

Sandip
Good Luck!!!
Rodney Hills
Honored Contributor

Re: Basic HPUX Question

If column A is the "key" to each of the files, then-

join -j1 1 -j2 1 -o1.1,1.2,2.2 ABC XYZ >NEWXYZ

Should work for you. This assumes blank or tab is the field seperator.

Use -t: if you wanted to use ":" as seperator.
Use -a2 to send unmatched lines to STDERR.

Hope this helps

-- Rod Hills

There be dragons...
Leif Halvarsson_2
Honored Contributor

Re: Basic HPUX Question

Hi

paste is the most easy if the same line numbers in the two files shall be matched. In other cases (and if it is a one to many matching relation you have to use join). Note , if using join the files need to be sorted on the matching column.
Chia-Wei
Advisor

Re: Basic HPUX Question

Hi Mark,
Assuming tab as the deliminator, do this :
paste XYZ ABC | cut -f 1,2,4 > JOINED

Use the -d option to specify deliminator if tab is not the correct one. man cut for more information.
Joseph A Benaiah_1
Regular Advisor

Re: Basic HPUX Question

Mark,

You can combine the files as follows:

pr -m -t -s' ' XYZ ABC | awk '{ print $1, $2, $4 }'

Cheers,

Joseph.