Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can try the following command:</p> <pre><code>awk -f a.awk 2.txt 1.txt &gt; 3.txt </code></pre> <p>where <code>a.awk</code> is:</p> <pre><code>BEGIN { FS=OFS="|" } NR==FNR{ a[$1]=$2 next } { if ($1 in a) $(NF+1)=a[$1] else $(NF+1)="NULL" print } </code></pre> <p>with output:</p> <pre><code>CID|UID|Key|sis_URL|bro_URL 1|D000108|RDHQFKQIGNGIED|http://sis.gov/regno=0000870779 1|D000108|RDHQFKQIGNGIED|http://sis.gov/regno=0014992622 1|D000644|RDHQFKQIGNGIED|http://sis.gov/regno=0000870779 1|D000644|RDHQFKQIGNGIED|http://sis.gov/regno=0014992622 1|D002331|RDHQFKQIGNGIED|http://sis.gov/regno=0000870779 1|D002331|RDHQFKQIGNGIED|http://sis.gov/regno=0014992622 11|C024565|WSLDOOZREJYCGB|http://sis.gov/regno=0000107062|http://bro.gov/nmbr=0149 13|C009947|PBKONEOXTCPAFI|http://sis.gov/regno=0000120821|http://bro.gov/nmbr=0119 13|C009947|PBKONEOXTCPAFI|http://sis.gov/regno=0063697187|http://bro.gov/nmbr=0119 </code></pre> <p><strong>Explanation</strong></p> <ul> <li>We read the data in <code>2.txt</code> into the associative array <code>a</code></li> <li>The test <code>NR==FNR</code> is used to match only the first file on the command line, that is the file <code>2.txt</code></li> <li>The <code>next</code> statement is important so that the next rules are not executed for <code>2.txt</code></li> <li>The second rule (the one containing the <code>if</code> test) is then executed only for <code>1.txt</code> but the information from <code>2.txt</code> is still available through the array <code>a</code></li> <li>If the first field matches a field in the first column in <code>2.txt</code>, that is: <code>if ($1 in a)</code>, then we insert that value at the end of the line (<code>NF</code> is the number of fields (that is: columns) read from <code>1.txt</code>)</li> <li>If there is no match, we insert the string <code>"NULL"</code></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload