I have to combine several files.
This is for two files.
1.txt
All Sequences B * 07: 02: 01 ABCDEB * 07: 33: 01ABCD B * 07: 41Ab
2.txt
All sequence B * 07: 02: 01FGHIJI B * 07: 33: 01EFGH B * 07: 41CD
is a delimited tab (\ t)
I want to get results like
B * 07: 02: 01ABCDEFGHI B * 07: 33: 01ABCDFG B * 07: 41 ABCD
I tried the following.
awk -F "\ t" '{key = $ 1} FNR == NR {line [key] = $ 0; Next line {print line [$ 1], $ 2} '$ 1 $ 2 & gt; Output_2.txt
Then the results like
all the sequence ^ m sequence ^ MB * 07: 02: 01ABCDE ^ MFGHIJ B * 07: 33: 01 ABCD ^ M EFG B * 07: 41 AB ^ M CD
How can I make more clear and what exactly do I want
Thanks!
This can work:
awk 'FNR == NR {a [$ 1] = $ 2; Next} FNR & gt; 1 {Print $ 0 a [$ 1]} '2.txt 1.txt B * 07: 02: 01ABCDEFGHIG B * 07: 33: 01ABCDEFG B * 07: 41ABCD
How it works:
awk 'FNR == NR {# for the first file only (2.txt) to use a [$ 1] = $ 2 # data Read the data in the array $ 2 as the key and $ 2 as the next value) # Go to next record FNR & gt; 1 {# Skip the first record of the second file (1.txt) Print $ 0 Print a complete record from a [$ 1]} # 1.txt, and use the $ 1 data from the array key '2.txt 1.txt # Read the files as
Comments
Post a Comment