<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: merging of columns from two files in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731435#M721844</link>
    <description>You could use join, but you don't have much flexibility. The command you would use is-&lt;BR /&gt;&lt;BR /&gt;join -a 1 -a 2 -e \* -o 1.1,1.2,2.2 file1 file2&lt;BR /&gt;&lt;BR /&gt;This will place a "*" in the fields that are missing. Unfortunately if their are any missing time stamps in file1, they will be replaced with "*" also.&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
    <pubDate>Fri, 24 May 2002 20:50:25 GMT</pubDate>
    <dc:creator>Rodney Hills</dc:creator>
    <dc:date>2002-05-24T20:50:25Z</dc:date>
    <item>
      <title>merging of columns from two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731429#M721838</link>
      <description>I have a question , I have two files as shown below&lt;BR /&gt;&lt;BR /&gt;FILE1   FILE2 &lt;BR /&gt;Time cpu  Time memory&lt;BR /&gt;0:00 45  0:00 15&lt;BR /&gt;0:15 72  0:15 82&lt;BR /&gt;0:30 15  0:30 15&lt;BR /&gt;0:45 95  0:45 25&lt;BR /&gt;1:00   1:00 40&lt;BR /&gt;1:15   1:15 25&lt;BR /&gt;1:30   1:30 45&lt;BR /&gt;&lt;BR /&gt;***************************************&lt;BR /&gt;I want to create a new file by merging the above two files as below:&lt;BR /&gt;&lt;BR /&gt;NEW FILE  &lt;BR /&gt;Time cpu memory&lt;BR /&gt;0:00 45 15&lt;BR /&gt;0:15 72 82&lt;BR /&gt;0:30 15 15&lt;BR /&gt;0:45 95 25&lt;BR /&gt;1:00  40&lt;BR /&gt;1:15  25&lt;BR /&gt;1:30  45&lt;BR /&gt;&lt;BR /&gt;*****************&lt;BR /&gt; I tried to merge the fields using pr and paste  commands. But i am getting a misaligned output file as follows:&lt;BR /&gt;&lt;BR /&gt;OUTPUT  FILE  &lt;BR /&gt;Time cpu memory&lt;BR /&gt;0:00 45 15&lt;BR /&gt;0:15 72 82&lt;BR /&gt;0:30 15 15&lt;BR /&gt;0:45 95 25&lt;BR /&gt;1:00 40 &lt;BR /&gt;1:15 25 &lt;BR /&gt;1:30 45 &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;can any one suggest a script to get the correct output file. can we use awk for this.??&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Narasimham</description>
      <pubDate>Fri, 24 May 2002 17:34:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731429#M721838</guid>
      <dc:creator>Narasimham</dc:creator>
      <dc:date>2002-05-24T17:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: merging of columns from two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731430#M721839</link>
      <description>Maybe I'm not seeing something, but the example of what you want your new file to look like and what your current attempt output look the same.  &lt;BR /&gt;&lt;BR /&gt;I don't see the problem.</description>
      <pubDate>Fri, 24 May 2002 17:48:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731430#M721839</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2002-05-24T17:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: merging of columns from two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731431#M721840</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Please look at this link :&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x66ae6af52b04d5118fef0090279cd0f9,00.html" target="_blank"&gt;http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x66ae6af52b04d5118fef0090279cd0f9,00.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;There is a good script also there.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Manoj Srivastava</description>
      <pubDate>Fri, 24 May 2002 17:48:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731431#M721840</guid>
      <dc:creator>MANOJ SRIVASTAVA</dc:creator>
      <dc:date>2002-05-24T17:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: merging of columns from two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731432#M721841</link>
      <description>Once again i am submitting my question&lt;BR /&gt;&lt;BR /&gt;This may give you more clarity&lt;BR /&gt;FILE1 &lt;BR /&gt;&lt;BR /&gt;Time cpu&lt;BR /&gt;0:00 45&lt;BR /&gt;0:15 72&lt;BR /&gt;0:30 15&lt;BR /&gt;0:45 95&lt;BR /&gt;1:00 &lt;BR /&gt;1:15 &lt;BR /&gt;1:30 &lt;BR /&gt;*****************&lt;BR /&gt;FILE2 &lt;BR /&gt;Time memory&lt;BR /&gt;0:00 15&lt;BR /&gt;0:15 82&lt;BR /&gt;0:30 15&lt;BR /&gt;0:45 25&lt;BR /&gt;1:00 40&lt;BR /&gt;1:15 25&lt;BR /&gt;1:30 45&lt;BR /&gt;&lt;BR /&gt;***************&lt;BR /&gt;As there are only four records under cpu field the values from memory are getting shifted to the left side as below;&lt;BR /&gt;&lt;BR /&gt;OUTPUT  FILE  &lt;BR /&gt;Time cpu memory&lt;BR /&gt;0:00 45 15&lt;BR /&gt;0:15 72 82&lt;BR /&gt;0:30 15 15&lt;BR /&gt;0:45 95 25&lt;BR /&gt;1:00 40 &lt;BR /&gt;1:15 25 &lt;BR /&gt;1:30 45 &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I think you understand my problem.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 24 May 2002 17:54:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731432#M721841</guid>
      <dc:creator>Narasimham</dc:creator>
      <dc:date>2002-05-24T17:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: merging of columns from two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731433#M721842</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;here is the solution may not be a straight one though&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;paste file2 file1 |awk '{print $1,$2,$4}'&lt;BR /&gt;&lt;BR /&gt;o/p looks like this&lt;BR /&gt;&lt;BR /&gt;Time memory cpu&lt;BR /&gt;0:00 15 45&lt;BR /&gt;0:15 82 72&lt;BR /&gt;0:30 15 15&lt;BR /&gt;0:45 25 95&lt;BR /&gt;1:00 40 &lt;BR /&gt;1:15 25 &lt;BR /&gt;1:30 45 &lt;BR /&gt;&lt;BR /&gt;better than the previous one.&lt;BR /&gt;&lt;BR /&gt;Manoj Srivastava&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 24 May 2002 19:24:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731433#M721842</guid>
      <dc:creator>MANOJ SRIVASTAVA</dc:creator>
      <dc:date>2002-05-24T19:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: merging of columns from two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731434#M721843</link>
      <description>Manoj&lt;BR /&gt;&lt;BR /&gt;I know that  we can do this way.&lt;BR /&gt;but what happens for instance, if first column has less number of records than the second????&lt;BR /&gt;&lt;BR /&gt;can we use join for this??&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Narasimham</description>
      <pubDate>Fri, 24 May 2002 19:34:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731434#M721843</guid>
      <dc:creator>Narasimham</dc:creator>
      <dc:date>2002-05-24T19:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: merging of columns from two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731435#M721844</link>
      <description>You could use join, but you don't have much flexibility. The command you would use is-&lt;BR /&gt;&lt;BR /&gt;join -a 1 -a 2 -e \* -o 1.1,1.2,2.2 file1 file2&lt;BR /&gt;&lt;BR /&gt;This will place a "*" in the fields that are missing. Unfortunately if their are any missing time stamps in file1, they will be replaced with "*" also.&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Fri, 24 May 2002 20:50:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731435#M721844</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2002-05-24T20:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: merging of columns from two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731436#M721845</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;This script should meet your needs:&lt;BR /&gt;&lt;BR /&gt;======================================&lt;BR /&gt;bash-2.05a# cat ./combine&lt;BR /&gt;#!/sbin/sh&lt;BR /&gt; &lt;BR /&gt;echo `head -1 file1` `head -1 file2 | cut -d" " -f2-`&lt;BR /&gt;for i in `cat file1 file2 | grep ':' | awk '{print $1}' | sort -n | uniq`&lt;BR /&gt;do &lt;BR /&gt;  echo $i `grep $i file1 | cut -d" " -f2-` `grep $i file2 | cut -d" " -f2-`&lt;BR /&gt;done&lt;BR /&gt;======================================&lt;BR /&gt;&lt;BR /&gt;Output of my testing:&lt;BR /&gt;&lt;BR /&gt;======================================&lt;BR /&gt;bash-2.05a# cat file1&lt;BR /&gt;Time cpu &lt;BR /&gt;0:00 45 &lt;BR /&gt;0:15 72 &lt;BR /&gt;0:30 15 &lt;BR /&gt;0:45 95 &lt;BR /&gt;1:00 &lt;BR /&gt;1:15 &lt;BR /&gt;1:30 &lt;BR /&gt;&lt;BR /&gt;bash-2.05a# cat file2&lt;BR /&gt;Time memory &lt;BR /&gt;0:00 15 &lt;BR /&gt;0:15 82 &lt;BR /&gt;0:30 15 &lt;BR /&gt;0:45 25 &lt;BR /&gt;1:00 40 &lt;BR /&gt;1:15 25 &lt;BR /&gt;1:30 45 &lt;BR /&gt;&lt;BR /&gt;bash-2.05a# ./combine&lt;BR /&gt;Time cpu memory&lt;BR /&gt;0:00 45 15&lt;BR /&gt;0:15 72 82&lt;BR /&gt;0:30 15 15&lt;BR /&gt;0:45 95 25&lt;BR /&gt;1:00 40&lt;BR /&gt;1:15 25&lt;BR /&gt;1:30 45&lt;BR /&gt;======================================&lt;BR /&gt;&lt;BR /&gt;The for condition is needed to ensure that all timings in both files are accounted for even when timings in one file does not exist in other.&lt;BR /&gt;&lt;BR /&gt;Hope this helps. Regards.&lt;BR /&gt;&lt;BR /&gt;Steven Sim Kok Leong</description>
      <pubDate>Sat, 25 May 2002 01:02:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731436#M721845</guid>
      <dc:creator>Steven Sim Kok Leong</dc:creator>
      <dc:date>2002-05-25T01:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: merging of columns from two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731437#M721846</link>
      <description>HI,&lt;BR /&gt;&lt;BR /&gt;If the files are sorted on first columns, then you can use "join command"&lt;BR /&gt;join FILE1 FILE2&lt;BR /&gt;&lt;BR /&gt;join command has another options also, for which you can refer to "man join"&lt;BR /&gt;&lt;BR /&gt;In your case, I think what you can do is remove the title, sort FILE1 and FILE2, then join the files and then add the title again.&lt;BR /&gt;&lt;BR /&gt;Hope this helps,&lt;BR /&gt;Regards,&lt;BR /&gt;Suhas&lt;BR /&gt;</description>
      <pubDate>Mon, 27 May 2002 03:52:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731437#M721846</guid>
      <dc:creator>Suhas_3</dc:creator>
      <dc:date>2002-05-27T03:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: merging of columns from two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731438#M721847</link>
      <description>Hi,&lt;BR /&gt;1. Take of the headers (join only works on sorted files)&lt;BR /&gt;2. #join file1 file2&lt;BR /&gt;3. Add the headers&lt;BR /&gt;&lt;BR /&gt;Hope this helps,&lt;BR /&gt;Tom</description>
      <pubDate>Mon, 27 May 2002 04:01:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731438#M721847</guid>
      <dc:creator>Tom Geudens</dc:creator>
      <dc:date>2002-05-27T04:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: merging of columns from two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731439#M721848</link>
      <description>Hi....Steven &lt;BR /&gt;&lt;BR /&gt;The output is not as reqd.  .. still the last four rows of the file2 are shfting to the left.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Narasimham&lt;BR /&gt;</description>
      <pubDate>Tue, 28 May 2002 13:09:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731439#M721848</guid>
      <dc:creator>Narasimham</dc:creator>
      <dc:date>2002-05-28T13:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: merging of columns from two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731440#M721849</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I see what you mean. I have now made script modifications to shift the columns to the right:&lt;BR /&gt;&lt;BR /&gt;=========================================&lt;BR /&gt;#!/sbin/sh&lt;BR /&gt; &lt;BR /&gt;echo `head -1 file1` `head -1 file2 | cut -d" " -f2-`&lt;BR /&gt;for i in `cat file1 file2 | grep ':' | awk '{print $1}' | sort -n | uniq`&lt;BR /&gt;do&lt;BR /&gt;  col1=`grep $i file1 | cut -d" " -f2-`&lt;BR /&gt;  if echo $col1 | grep [1-9] &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;  then&lt;BR /&gt;    echo $i `grep $i file1 | cut -d" " -f2-` `grep $i file2 | cut -d" " -f2-`&lt;BR /&gt;  else&lt;BR /&gt;    echo $i "  " `grep $i file2 | cut -d" " -f2-`&lt;BR /&gt;  fi&lt;BR /&gt;done&lt;BR /&gt;=========================================&lt;BR /&gt;&lt;BR /&gt;Hope this helps. Regards.&lt;BR /&gt;&lt;BR /&gt;Steven Sim Kok Leong&lt;BR /&gt;</description>
      <pubDate>Tue, 28 May 2002 13:18:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731440#M721849</guid>
      <dc:creator>Steven Sim Kok Leong</dc:creator>
      <dc:date>2002-05-28T13:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: merging of columns from two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731441#M721850</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Due to limitations of the forum in displaying consecutive spaces, I cannot display the two spaces within the double quotes in my posting.&lt;BR /&gt;&lt;BR /&gt;To explain, the line:&lt;BR /&gt;&lt;BR /&gt;echo $i "  " `grep $i file2 | cut -d" " -f2-`&lt;BR /&gt;&lt;BR /&gt;is explicitly the following:&lt;BR /&gt;&lt;BR /&gt;echo $i "&amp;lt;1st space&amp;gt;&amp;lt;2nd space&amp;gt;" `grep $i file2 | cut -d" " -f2-`&lt;BR /&gt;&lt;BR /&gt;Hope this helps. Regards.&lt;BR /&gt;&lt;BR /&gt;Steven Sim Kok Leong</description>
      <pubDate>Tue, 28 May 2002 13:22:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731441#M721850</guid>
      <dc:creator>Steven Sim Kok Leong</dc:creator>
      <dc:date>2002-05-28T13:22:37Z</dc:date>
    </item>
    <item>
      <title>Re: merging of columns from two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731442#M721851</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;use typeset&lt;BR /&gt;&lt;BR /&gt;I copied your files to $HOME/tmp f1 f2 on my machine&lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;cd&lt;BR /&gt;typeset -L6 a=$1&lt;BR /&gt;typeset -R6 b=$2&lt;BR /&gt;typeset -R7 d=$4&lt;BR /&gt;paste tmp/f1 tmp/f2|while read a b c d&lt;BR /&gt;do&lt;BR /&gt;echo "$a$b$d"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Gives&lt;BR /&gt;&lt;BR /&gt;Time     cpu memory&lt;BR /&gt;0:00      45     15&lt;BR /&gt;0:15      72     82&lt;BR /&gt;0:30      15     15&lt;BR /&gt;0:45      95     25&lt;BR /&gt;1:00    1:00&lt;BR /&gt;1:15    1:15&lt;BR /&gt;1:30    1:30&lt;BR /&gt;&lt;BR /&gt;That is neat enough&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;              Steve Steel</description>
      <pubDate>Tue, 28 May 2002 13:37:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731442#M721851</guid>
      <dc:creator>Steve Steel</dc:creator>
      <dc:date>2002-05-28T13:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: merging of columns from two files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731443#M721852</link>
      <description>Rod Hills &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Your join command working  fine for me &lt;BR /&gt;&lt;BR /&gt;Thanks for the help&lt;BR /&gt;&lt;BR /&gt;Narasimham</description>
      <pubDate>Tue, 28 May 2002 14:05:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/merging-of-columns-from-two-files/m-p/2731443#M721852</guid>
      <dc:creator>Narasimham</dc:creator>
      <dc:date>2002-05-28T14:05:16Z</dc:date>
    </item>
  </channel>
</rss>

