<?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: Combine two text files in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765367#M894767</link>
    <description>Hi Clay,&lt;BR /&gt;&lt;BR /&gt;Okay, you convinced me. I could follow most of your script but I don't understand what TDIR=${TMPDIR:-/var/tmp} is supposed to do. I know you are making temporary files. I commented the rm statement out and the temporary files are created in /var/tmp.  &lt;BR /&gt;&lt;BR /&gt;Thanks for your help.&lt;BR /&gt;&lt;BR /&gt;Derek Card</description>
    <pubDate>Wed, 17 Jul 2002 18:12:18 GMT</pubDate>
    <dc:creator>Derek Card</dc:creator>
    <dc:date>2002-07-17T18:12:18Z</dc:date>
    <item>
      <title>Combine two text files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765355#M894755</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have two text files that have a starting date in one file and an ending date in the other file.&lt;BR /&gt;&lt;BR /&gt;File "startdates"&lt;BR /&gt;1-Jan-1999&lt;BR /&gt;1-Jan-1999&lt;BR /&gt;2-Jan-1999&lt;BR /&gt;&lt;BR /&gt;File "enddates"&lt;BR /&gt;12-Jun-1999&lt;BR /&gt;----------&lt;BR /&gt;31-Mar-2002&lt;BR /&gt;&lt;BR /&gt;I would like to combine each line of these two files into 1 line&lt;BR /&gt;like this:&lt;BR /&gt;1-Jan-1999  12-Jun-1999&lt;BR /&gt;1-Jan-1999  ----------&lt;BR /&gt;2-Jan-1999  31-Mar-2002&lt;BR /&gt;&lt;BR /&gt;The actual file has thousands of entries. I am fairly new to UNIX. Is there a command to easily do this?&lt;BR /&gt;&lt;BR /&gt;TIA, Derek Card</description>
      <pubDate>Tue, 16 Jul 2002 20:45:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765355#M894755</guid>
      <dc:creator>Derek Card</dc:creator>
      <dc:date>2002-07-16T20:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two text files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765356#M894756</link>
      <description>Derek, this is about as easy as it gets.&lt;BR /&gt;&lt;BR /&gt;paste startdates enddates &amp;gt; bothdates&lt;BR /&gt;&lt;BR /&gt;Man paste for details.&lt;BR /&gt;</description>
      <pubDate>Tue, 16 Jul 2002 20:46:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765356#M894756</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-07-16T20:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two text files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765357#M894757</link>
      <description>There is - it is the paste command. Ex paste file1 file2. Do a man paste for options.</description>
      <pubDate>Tue, 16 Jul 2002 20:46:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765357#M894757</guid>
      <dc:creator>Dave Chamberlin</dc:creator>
      <dc:date>2002-07-16T20:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two text files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765358#M894758</link>
      <description>Hi Derek&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Use paste startdates enddates &amp;gt; test to get the result .&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Manoj Srivastava</description>
      <pubDate>Tue, 16 Jul 2002 20:57:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765358#M894758</guid>
      <dc:creator>MANOJ SRIVASTAVA</dc:creator>
      <dc:date>2002-07-16T20:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two text files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765359#M894759</link>
      <description>Another option is pr -tm startdates enddates &amp;gt; bothdates.&lt;BR /&gt;&lt;BR /&gt;The only advantage this has over paste is some formatting (although there's no advantage with your example.&lt;BR /&gt;&lt;BR /&gt;But if the lengths of the lines in startdates varies, for example:&lt;BR /&gt;&lt;NO date="" has="" been="" specified=""&gt;&lt;BR /&gt;10-January-1999&lt;BR /&gt;1-March-1999&lt;BR /&gt;2-May-1999&lt;BR /&gt;&lt;BR /&gt;then the output of paste would be:&lt;BR /&gt;No date has been specified      22-Jan-1999&lt;BR /&gt;10-January-1999         12-Jun-1999&lt;BR /&gt;1-March-1999    ----------&lt;BR /&gt;2-May-1999      31-Mar-2002&lt;BR /&gt;&lt;BR /&gt;(I added 22-Jan-1999 to make the number of items/file equal)&lt;BR /&gt;&lt;BR /&gt;with  pr -tm&lt;BR /&gt;No date has been specified          22-Jan-1999&lt;BR /&gt;10-January-1999                     12-Jun-1999&lt;BR /&gt;1-March-1999                        ----------&lt;BR /&gt;2-May-1999                          31-Mar-2002&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/NO&gt;</description>
      <pubDate>Tue, 16 Jul 2002 21:36:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765359#M894759</guid>
      <dc:creator>Ian Kidd_1</dc:creator>
      <dc:date>2002-07-16T21:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two text files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765360#M894760</link>
      <description>I was afraid that my extra white spaces would vanish in my reply above.  The attachment I included should show the correct view (I hope)</description>
      <pubDate>Tue, 16 Jul 2002 21:41:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765360#M894760</guid>
      <dc:creator>Ian Kidd_1</dc:creator>
      <dc:date>2002-07-16T21:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two text files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765361#M894761</link>
      <description>Hello again,&lt;BR /&gt;&lt;BR /&gt;Thank you for all your replies. I'm afraid that I didn't quite get enough information and now I'm really stuck. These two date files have an additional entry called ID Number. I really need&lt;BR /&gt;to combine the Id Number, the start dates, and the end dates into 1 line. I don't even know where to begin. &lt;BR /&gt;&lt;BR /&gt;File "startdates" &lt;BR /&gt;1-Jan-1999  1009&lt;BR /&gt;1-Jan-1999  1010&lt;BR /&gt;2-Jan-1999  1011&lt;BR /&gt;5-Jan-1999  1012&lt;BR /&gt;&lt;BR /&gt;File "enddates" &lt;BR /&gt;12-Jun-1999  1009&lt;BR /&gt; ---------- 1010&lt;BR /&gt;31-Mar-2002  1011&lt;BR /&gt;&lt;BR /&gt;1009  1-Jan-1999 12-Jun-1999 &lt;BR /&gt;1010  1-Jan-1999 ---------- &lt;BR /&gt;1011  2-Jan-1999 31-Mar-2002&lt;BR /&gt;&lt;BR /&gt;If there is no matching ID Number, no output is needed.&lt;BR /&gt;I've been looking at awk. Is that what I need to use?&lt;BR /&gt;&lt;BR /&gt;Thanks, Derek Card</description>
      <pubDate>Wed, 17 Jul 2002 17:14:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765361#M894761</guid>
      <dc:creator>Derek Card</dc:creator>
      <dc:date>2002-07-17T17:14:42Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two text files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765362#M894762</link>
      <description>When I saw this post yesterday I thought this was a very hokey data model but now it makes a bit more sense. You could use awk (or Perl) for this but today I think a little sort and join will do the trick.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;TDIR=${TMPDIR:-/var/tmp}&lt;BR /&gt;PID=${$}&lt;BR /&gt;T1=${TDIR}/X${PID}_1.tmp&lt;BR /&gt;T2=${TDIR}/X${PID}_2.tmp&lt;BR /&gt;&lt;BR /&gt;sort -k2,2b startdates &amp;gt; ${T1}&lt;BR /&gt;sort -k2,2b enddates &amp;gt; ${T2}&lt;BR /&gt;join -j 2 ${T1} ${T2} | sort -k1,1n&lt;BR /&gt;STAT=${?}&lt;BR /&gt;rm -f ${T1} ${T2}&lt;BR /&gt;exit ${STAT}&lt;BR /&gt;&lt;BR /&gt;That should be a complete solution. (If my expert typing is okay.)&lt;BR /&gt;&lt;BR /&gt;Man sort, join for details.&lt;BR /&gt;&lt;BR /&gt;Clay&lt;BR /&gt;</description>
      <pubDate>Wed, 17 Jul 2002 17:20:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765362#M894762</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-07-17T17:20:11Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two text files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765363#M894763</link>
      <description>hi , &lt;BR /&gt;&lt;BR /&gt;what about  :&lt;BR /&gt;(you can put the output in a file)&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;startDateFile=./startdates&lt;BR /&gt;endDateFile=./enddates&lt;BR /&gt;&lt;BR /&gt;while read -e startDate idNr&lt;BR /&gt;do&lt;BR /&gt;  while read -e endDate idNr2&lt;BR /&gt;  do&lt;BR /&gt;    if [ "${idNr}" = "${idNr2}" ]&lt;BR /&gt;    then&lt;BR /&gt;        echo "${idNr} ${startDate} ${endDate}"&lt;BR /&gt;    fi&lt;BR /&gt;done &amp;lt; ${endDateFile}&lt;BR /&gt;done &amp;lt; ${startDateFile}&lt;BR /&gt;&lt;BR /&gt;regards, &lt;BR /&gt;&lt;BR /&gt;Steven&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 17 Jul 2002 17:33:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765363#M894763</guid>
      <dc:creator>Steven Mertens</dc:creator>
      <dc:date>2002-07-17T17:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two text files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765364#M894764</link>
      <description>Hi&lt;BR /&gt;There is a (perhaps not so known) command in HP-UX called "join" which is a kind of "relational operator". It matches fields in two files. The files need to be sorted on the matching fields.&lt;BR /&gt;&lt;BR /&gt;In your case the "basic" of your script should look somthing like.&lt;BR /&gt;&lt;BR /&gt;join -j1 3 -j2 1 -o 1.1 2.2 2.1 startfile endfile&lt;BR /&gt;&lt;BR /&gt;Which means it matches field 3 of startfile with field  1 of endfile and output field 1 of startfile and field 2 and 1 of endfile.&lt;BR /&gt;&lt;BR /&gt;Have a look at man join.</description>
      <pubDate>Wed, 17 Jul 2002 17:39:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765364#M894764</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2002-07-17T17:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two text files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765365#M894765</link>
      <description>Thanks!&lt;BR /&gt;&lt;BR /&gt;Clay, I copied and pasted your script and it works but I just tried the script that Leif posted. It works too and is simpler.&lt;BR /&gt;I think I will use Leif's.&lt;BR /&gt;&lt;BR /&gt;Thanks again, Derek Card&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 17 Jul 2002 17:44:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765365#M894765</guid>
      <dc:creator>Derek Card</dc:creator>
      <dc:date>2002-07-17T17:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two text files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765366#M894766</link>
      <description>Well Derek, I considered the simple join as well BUT I ruled it out for these reasons:&lt;BR /&gt;&lt;BR /&gt;Join requires data sorted in LEXICAL order (not numeric) and while your data files appear to be sorted, I couldn't know for sure.&lt;BR /&gt;&lt;BR /&gt;You probably want the data out in numeric order. That's the reason for the final sort using a -n key otherwise the order might be 1,10,100,1000,2,20,200,2000 rather than 1,2,10,20,1000,2000.&lt;BR /&gt;&lt;BR /&gt;If you KNOW that you incoming data is lexicographically sorted the the 'one-liner' will work. I'm one of those 'better safe than sorry' type guys.&lt;BR /&gt;&lt;BR /&gt;I'm not saying that Leif's solution was in any sense wrong.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Food for thought, Clay&lt;BR /&gt;</description>
      <pubDate>Wed, 17 Jul 2002 17:53:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765366#M894766</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-07-17T17:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two text files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765367#M894767</link>
      <description>Hi Clay,&lt;BR /&gt;&lt;BR /&gt;Okay, you convinced me. I could follow most of your script but I don't understand what TDIR=${TMPDIR:-/var/tmp} is supposed to do. I know you are making temporary files. I commented the rm statement out and the temporary files are created in /var/tmp.  &lt;BR /&gt;&lt;BR /&gt;Thanks for your help.&lt;BR /&gt;&lt;BR /&gt;Derek Card</description>
      <pubDate>Wed, 17 Jul 2002 18:12:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765367#M894767</guid>
      <dc:creator>Derek Card</dc:creator>
      <dc:date>2002-07-17T18:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: Combine two text files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765368#M894768</link>
      <description>I could have simply used:&lt;BR /&gt;TDIR=/var/tmp&lt;BR /&gt;but instead, I used the conditional assignment: &lt;BR /&gt;TDIR=${TMPDIR:-/var/tmp}&lt;BR /&gt;&lt;BR /&gt;If the environment variable TMPDIR is defined then it's value is used otherwise /var/tmp is used. TMPDIR is a standard variable used by commands and many programs to define the temp directory name.&lt;BR /&gt;&lt;BR /&gt;Man sh-posix for details.&lt;BR /&gt;&lt;BR /&gt;Regards, Clay&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 17 Jul 2002 18:16:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/combine-two-text-files/m-p/2765368#M894768</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-07-17T18:16:17Z</dc:date>
    </item>
  </channel>
</rss>

