Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
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.

James R. Ferguson
Acclaimed Contributor

Re: Basic HPUX Question

Hi Mark:

See 'paste'.


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.

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


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.

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


You can combine the files as follows:

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