help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] combine


From: Greg Wooledge
Subject: Re: [Help-bash] combine
Date: Thu, 5 Apr 2018 08:42:32 -0400
User-agent: NeoMutt/20170113 (1.7.2)

On Wed, Apr 04, 2018 at 10:58:06PM +0000, Val Krem 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

https://mywiki.wooledge.org/BashProgramming/04

The first file can be read into an associative array that maps
"ABC1" to "Zc124" (you have to perform the capitalization at some
point, so why not now).

Then when you read the second file line-by-line, you simply replace
the first column with its value from the associative array.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]