AWK getline and join by step
AWK getline and join by step
(OP)
227/5000
Hello
I want to perform a join where AWK takes the name of a line in a first file, places it in fields 1 in the output file, then goes to a second file takes the extended names and places them in fields 2.
file_1:
AB-00050832
AB-00058394
AB-00050862
AB-00004123
file_2:
AB-00050832-18.....1....-8.900758
AB-00058394-10.....2....-7.981418
AB-00050832-24.....3....-7.634420
AB-00050862-10.....4....-7.621671
AB-00004123-1......5....-7.386272
AB-00058394-6.......6....-7.383604
AB-00050832-12....14....-7.038594
AB-00050862-6.....50....-6.701126
output:
AB-00050832.....AB-00050832-18.....1....-8.900758
........................AB-00050832-24.....3....-7.634420
........................AB-00050832-12....14....-7.038594
AB-00058394.....AB-00058394-10.....2....-7.981418
........................AB-00058394-6.......6....-7.383604
AB-00050862.....AB-00050862-10.....4....-7.621671
........................AB-00050862-6.....50....-6.701126
AB-00004123.....AB-00004123-1......5....-7.386272
I added points to better visualize, but they are not useful.
file_2 is:
- attached to file_1
- sorted according to file_1 following the order of file_1. It is just important to keep the order in which the name appears in file_1. I tried with a getline but I feel like there is something I can't unlock
He takes.
If you have an idea, thank you very much!
Hello
I want to perform a join where AWK takes the name of a line in a first file, places it in fields 1 in the output file, then goes to a second file takes the extended names and places them in fields 2.
file_1:
AB-00050832
AB-00058394
AB-00050862
AB-00004123
file_2:
AB-00050832-18.....1....-8.900758
AB-00058394-10.....2....-7.981418
AB-00050832-24.....3....-7.634420
AB-00050862-10.....4....-7.621671
AB-00004123-1......5....-7.386272
AB-00058394-6.......6....-7.383604
AB-00050832-12....14....-7.038594
AB-00050862-6.....50....-6.701126
output:
AB-00050832.....AB-00050832-18.....1....-8.900758
........................AB-00050832-24.....3....-7.634420
........................AB-00050832-12....14....-7.038594
AB-00058394.....AB-00058394-10.....2....-7.981418
........................AB-00058394-6.......6....-7.383604
AB-00050862.....AB-00050862-10.....4....-7.621671
........................AB-00050862-6.....50....-6.701126
AB-00004123.....AB-00004123-1......5....-7.386272
I added points to better visualize, but they are not useful.
file_2 is:
- attached to file_1
- sorted according to file_1 following the order of file_1. It is just important to keep the order in which the name appears in file_1. I tried with a getline but I feel like there is something I can't unlock
He takes.
If you have an idea, thank you very much!
RE: AWK getline and join by step
https://www.tek-tips.com/viewthread.cfm?qid=162923...
RE: AWK getline and join by step
file_1:
A
B
C
file_2:
A_1
C_2
C_1
B_4
A_2
A_3
B_1
output:
A....A_1
......A_2
......A_3
B.....B_4
.......B_1
C....C_2
......C_1
The order of appearance in file_1 is respected and the order of appearance in file_2 is respected. It's not really a join of two identical columns are merged.
RE: AWK getline and join by step
CODE
On the command line I changed the order of the files: so my judkil_file1.txt is your file_2
and my judkil_file2.txt is your file_1
RE: AWK getline and join by step
Is your problem already solved ? Here is my script from yesterday:
CODE
RE: AWK getline and join by step
However I would like to be able to put any size of pattern and not limited to a length of 11. What to put in the substr ?
RE: AWK getline and join by step
CODE
Other more flexible option, if you have a line like this:
CODE
CODE
CODE
CODE
CODE
CODE
RE: AWK getline and join by step
Thank you very much ! However, I have a syntax problem when I replace
CODE --> awk
CODE --> awk
RE: AWK getline and join by step
Here is the modified soure:
judkil_join.awk
CODE
In the files I added some lines with long key:
judkil_file1.txt
CODE
judkil_file2.txt
CODE
Now, when I run it I get this result:
CODE
RE: AWK getline and join by step
But key_array ,t's a field ($1) or just a number
CODE --> awk
RE: AWK getline and join by step
CODE
Look at the source above, where I'm using
CODE
RE: AWK getline and join by step
Thank you very much !
RE: AWK getline and join by step
For example, if we have this line i.e. this string in the field $0:
"AB-VERY_LONG_KEY-8......4....5.55"
then
split($0,key_array,"-")
creates this array of 3 strings
key_array = ("AB" | "VERY_LONG_KEY" | "8......4....5.55")
i.e.
key_array[1] = "AB"
key_array[2] = "VERY_LONG_KEY"
key_array[3] = "8......4....5.55"
and then we create the key with concatenation
key = key_array[1] "-" key_array[2]
with the result
key = "AB-VERY_LONG_KEY"
I hope that I helped you to understand, how to use awk to solve your problems
RE: AWK getline and join by step
Thank you! ;)