I want a easy to read perl program (the easier the better keep it simple please so I can expand it) to join 2 files using column 1 in both files. In file 1 if any row repeats the column 1 the lowest number should be used same for file 2 (file 2 f is an example of this) file 1 ------ a 0.000 b -0.234 c -0.456 d -0.678 e -1.345 file 2 ------ c -0.456 d -0.678 f -2.000 f -2.345 f -1.345 a -0.001 output ------- a 0.000 -0.0001 b -0.234 c -0.456 -0.456 d -0.678 -0.678 e -1.345 f -2.345
if there is no value from file 1 it should be
column1 <empty> < file 2>
Hello and thank you for contacting JustAnswer, a paid expert support site. My name is XXXXX XXXXX I'd be glad to assist you with your issue.
Do you know if the possible repeats from column 1 will be out of order? (a, a, b, a, etc)
yes they will be
do you understand the format it didnt help losing the line breaks
I believe so. The tricky bit will be making sure that the ones that are out of order are included.
Shouldn't be too hard. Will probably use a few arrays. I assume this will be done via command-line?
yes so plan was something like perl.pl file1 file2
if it is easier I can sort the data on column 1
I guess you still need the array anyway to compare what is in file 2 with file 1
Yup, so it probably wouldn't matter either way.
Ok, so the columns are separated by a space or tab?
can be either
again if it is a problem I can change it to whatever you want
Ok, just need to know what it should use to separate the columns. Either will work,
but best if you could assume white space just i.e. multiple spaces or multiple tabs
Ok. And when do you need this by?
asap but monday would work
if you need longer thats Ok as well but earlier would be better
I will probably have it done today or tomorrow at the latest. Just wanted to see what kind of timeframe we are looking at.
I have a good start on this, however, I have to leave for the day. I will probably work on this tonight and hope to have something for you in the morning. (GMT-5). Also, is the output provided the actual output expected for the two sets you provided?
apart from the formating yes it is
I dont care about the order of a b d e f in the output just the values
and each output should be 3 columns
if file1 value is missing the column should be left empty so the file2 value is aligned with all the other file 2 values
Got it. Almost done.
Ok, just working on the output. Trying to determine how to do this. Need to list the letters but can't rely on either file to have every letter. I can just cycle through a-z but if the files end at say "n", everything after that will be blank to z.
if its blank to z thats OK with me
I can sort that out afterwards
How's this look?
looks fine to me
Great. Here is the code:
great look likes it works fine
If you are familiar with perl, it shouldn't be too hard to understand. Basically, makes sure there are two file names given, then calls the function for both files. The function reads the files and gets the keys (letters) and values (numbers) and puts them into an associative array.
Then prints out based on keys a-z
do I just select excellent and submit for you to be paid?
That is it. I hope you are satisfied.
thanks I am
Have a great rest of your day.