I have two files and I'm trying to join them at a certain spot. I'd like to join them at the fourth column of the second file using the first column of the first. It's driving me nuts!
Here is what I'm trying:
join -j4 <(sort -k1 FirstFile.txt) <(sort -k4 SecondFile.txt)
FirstFile.txt:
24.136.152.171 US
24.136.152.171 US
24.136.152.171 US
SecondFile.txt
2014-08-03 00:00:00 User 24.136.152.171
2014-08-03 00:00:00 User 24.136.152.171
2014-08-03 00:00:00 User 24.136.152.171
Desired Output:
2014-08-03 00:00:00 User 24.136.152.171 US
2014-08-03 00:00:00 User 24.136.152.171 US
2014-08-03 00:00:00 User 24.136.152.171 US
The default output format of
join
is to print the join field, then remaining fields fromFILE1
and then the remaining fields fromFILE2
, unless the format is specified with-o
. Further, the option-j4
means that join field is the 4th field in both FILE1 and FILE2. So you need to split-j4
to-1 1 -2 4
.Try this:
You could us python.
Save the following in a file called
join.py
in your home area:then run it with