[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] combine
From: |
Pierre Gaston |
Subject: |
Re: [Help-bash] combine |
Date: |
Thu, 5 Apr 2018 08:45:54 +0300 |
On Thu, Apr 5, 2018 at 1:58 AM, Val Krem <address@hidden> wrote:
> Hi all,
> I have two files. The first file has two columns and the second file has
> about 15,000 columns and here is two samplesFile1
> ABC1 zc124
> ABC2 zc125
> ABC3 zc126
> ABC4 zc127
> File2 ( has about 15, 000 columns) ABC1 1 0 1 2 1....1
> ABC2 1 1 2 2 2....2
> ABC3 2 2 1 0 1...,0
>
> I want to merge the two files by the common column (column 1 in both
> files) and get the following output
> Result
> Zc124 1 0 1 2 1....1
> Zc125 1 1 2 2 2....2
> Zc126 2 2 1 0 1...,0
>
> Is it possible to read file 2 as a two variables? i.e., the first
> columns as one variable and the remaining columns as another available? If
> this is possible then I can combine the two files using the common
> variable between the two files.
>
> Thank you
>
>
It's probably better to not use bash for this but an external tool, if your
files are sorted like in your example, it could be that something like:
join file1 file2 | cut -d ' ' -f 2-
will do what you want
An alternative is to use awk.