Note that there are some explanatory texts on larger screens.

plurals
  1. POSearch and Append
    primarykey
    data
    text
    <p>I have been looking for a way to solve my problem, but have come to give up. I am pretty new to scripting so please bear with me. This is what I am trying to do:</p> <p>I have a file (let's call it file1) with 6 columns. On the first column there is an ID, and on the 7th there is an Alternate ID, but that whole column is empty:</p> <pre><code>ID col2 col3 col4 col5 col6 AltID AltID2 a a x 43 5 54 A1 D3 b f 4 44 9 51 B3 KL5 c h k 90 0 52 K9 JD3 ... </code></pre> <p>I have another set of files (6 to be precise) that each have 8 columns (they are tab delimited files). The 4th column contains IDs that match the ones from File1, col=ID, but in a random order. </p> <p>What I need to do is search for every ID in each row of the 1st column from File1 in the 4th column of the 6 other files I have, and when there is a match, put that match on the 7th column of File1.</p> <p>Another tricky thing is that some of these IDs are entirely missing (in which case they need to have an "x"), and other times they have more than one Alternate ID (in which case, I place them next to each other, in columns 7 and 8 of File1)</p> <p>I tried grep for a bit, but then stumbled upon people saying awk is actually better for this. I tried building a script and came up with this:</p> <pre><code>#! /bin/bash while read fn; do STR =$(echo -ne "${fn}" ; awk ' { if($4=="${fn}") printf "%s\t", $7} ' ./*.txt) echo $STR &gt; test.txt done &lt; dreg.txt </code></pre> <p>It obviously didn't work, and I know the code looks like I wasn't sure about what I was doing (I wasn't), but it's where I started. I was essentially trying to read a dummy file I created with only the first column with text, and then searching for every line on all the other text files in that directory. Then, if found, I was echoing the name of the ID, followed by the alternate IDs, hoping to get the following format:</p> <p>ID AltID AltID2</p> <p>My plan was to print these results into a file and then go from there, but it didn't work. It is not the most elegant solution, but like I said, I am not very proficient at this.</p> <p>Any help you guys have will be greatly appreciated. If you need another example or for me to clarify things, please let me know.</p> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    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. 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